Vehicle#
Car#
MyCar Class#
The MyCar class represents a complete vehicle dynamics simulation model. It integrates various subsystems essential for vehicle behavior simulation, including the chassis, wheels, and suspension components.
The class is composed of the following subclasses:
Chassis: Represents the main body of the vehicle, including mass, dimensions, and inertia properties.
Wheel: Four instances of the Wheel class represent the front-left, front-right, rear-left, and rear-right wheels.
Suspension: Four instances of the Suspension class simulate the dynamic response of the suspension system at each wheel.
- class pymycar.Vehicle.car.MyCar(chassis=None, left_rear_wheel=None, right_rear_wheel=None, left_front_wheel=None, right_front_wheel=None, left_rear_suspension=None, right_rear_suspension=None, left_front_suspension=None, right_front_suspension=None, path=None, result_folder_name='results')[source]#
Bases:
objectThe MyCar class integrates the vehicle dynamics subsystems: chassis, wheels, and suspensions.
- Attributes:
- chassisChassis
Represents the main vehicle body.
- left_rear_wheelWheel
Instance of the Wheel class for the rear-left wheel.
- right_rear_wheelWheel
Instance of the Wheel class for the rear-right wheel.
- left_front_wheelWheel
Instance of the Wheel class for the front-left wheel.
- right_front_wheelWheel
Instance of the Wheel class for the front-right wheel.
- left_rear_suspensionSuspension
Instance of the Suspension class for the rear-left suspension.
- right_rear_suspensionSuspension
Instance of the Suspension class for the rear-right suspension.
- left_front_suspensionSuspension
Instance of the Suspension class for the front-left suspension.
- right_front_suspensionSuspension
Instance of the Suspension class for the front-right suspension.
Methods
__init__(chassis, left_rear_wheel, right_rear_wheel, left_front_wheel, right_front_wheel, left_rear_suspension, right_rear_suspension, left_front_suspension, right_front_suspension)
Initializes the MyCar instance with provided subsystem objects.
save_log_info(logger)
Logs the simulation parameters of the vehicle and its subsystems.
- save_log_info(logger)[source]#
Log the simulation parameters of the vehicle and its subsystems.
- Parameters:
- loggerlogging.Logger
An instance of a logger to log the details.
Notes
The logger outputs detailed information for the following components: - Chassis - Each of the four wheels - Each of the four suspension systems
Chassis#
Chassis Class#
The Chassis class represents the physical properties and state of the vehicle’s chassis in the simulation. It includes geometric dimensions, mass, inertia properties, and aerodynamic characteristics.
#
# |<--rear_axle_to_com-->|<--front_axle_to_com-->|
#
# |.....|
# |---|.....|-------------\ | |
# | / \ \-----------------------|...|--------| ---
# | | | / \
# | | | |
# | | | |
# | | com | |
# | rear_track * | front_track
# | | | |
# | | | |
# | | | |
# | | | \ /
# | \ / /-----------------------|...|--------| ---
# |---|.....|-------------/
# |.....|
#
#
Parameter |
Description |
|---|---|
front_axle_to_com |
distance between the front axle and the vehicle CoM |
rear_axle_to_com |
distance between the rear axle and the vehicle CoM |
wheelbase |
front_axle_to_com + rear_axle_to_com |
front_track |
front track |
rear_track |
rear track |
com_height |
CoM height |
total_mass |
total mass of the chassis |
inertia_x |
x-axis vehicle inertia (w.r.t. CoM) |
inertia_y |
y-axis vehicle inertia (w.r.t. CoM) |
inertia_z |
z-axis vehicle inertia (w.r.t. CoM) |
drag_coefficient |
aerodynamics drag coefficient |
lift_coefficient |
aerodynamics lift coefficient |
- class pymycar.Vehicle.chassis.Chassis(front_axle_to_com=None, rear_axle_to_com=None, front_track=None, rear_track=None, com_height=None, mass=None, inertia_x=None, inertia_y=None, inertia_z=None, drag_coefficient=None, lift_coefficient=None)[source]#
Bases:
objectThe Chassis class represents the physical properties and state of the vehicle’s chassis in the simulation. It includes geometric dimensions, mass, inertia properties, and aerodynamic characteristics.
- Attributes:
- front_axle_to_comfloat
The distance between the front axle and the vehicle’s center of mass (CoM). (default: 1.48 m)
- rear_axle_to_comfloat
The distance between the rear axle and the vehicle’s center of mass (CoM). (default: 1.12 m)
- wheelbasefloat
The total distance between the front and rear axles. It is the sum of front_axle_to_com and rear_axle_to_com.
- front_trackfloat
The width of the chassis at the front axle, representing the distance between the left and right front wheels. (default: 1.71 m)
- rear_trackfloat
The width of the chassis at the rear axle, representing the distance between the left and right rear wheels. (default: 1.62 m)
- com_heightfloat
The height of the center of mass (CoM) from the ground. (default: 0.4 m)
- massfloat
The total mass of the chassis. (default: 1400 kg)
- inertia_xfloat
The moment of inertia about the x-axis (roll axis) of the vehicle, with respect to the CoM. (default: 400 kg·m²)
- inertia_yfloat
The moment of inertia about the y-axis (pitch axis) of the vehicle, with respect to the CoM. (default: 2000 kg·m²)
- inertia_zfloat
The moment of inertia about the z-axis (yaw axis) of the vehicle, with respect to the CoM. (default: 1320 kg·m²)
- drag_coefficientfloat
The drag coefficient used for aerodynamic calculations. (default: 0.34)
- lift_coefficientfloat
The lift coefficient used for aerodynamic calculations. (default: 0.0)
Methods
__init__(front_axle_to_com, rear_axle_to_com, front_track, rear_track, com_height, mass, inertia_x, inertia_y, inertia_z, drag_coefficient, lift_coefficient)
Initializes the chassis with the specified or default parameters.
update_state(dt)
Updates the chassis’s position and orientation based on the velocity and angular velocity for the given time step (dt).
save_state()
Saves the current state of the chassis, including CAD data, at the current simulation step.
set_velocity(vx, vy, vz, roll_rate, pitch_rate, yaw_rate)
Sets the chassis’s linear and angular velocities, including both translational and rotational components.
print_info()
Prints the current state of the chassis, including its position, orientation, velocity, and angular velocity.
update_chassis_data(**kwargs)
Updates chassis parameters dynamically based on the provided keyword arguments.
save_log_info(logger)
Logs the chassis parameters in a tabular format using the provided logger instance.
- print_info()[source]#
Prints the current state of the chassis, including its position, orientation, velocity, and angular velocity.
- save_log_info(logger)[source]#
Logs the chassis parameters in a tabular format using the provided logger instance.
- Parameters:
- loggerlogging.Logger
An instance of a logger object to record the chassis parameters.
- set_velocity(vx, vy, vz, roll_rate, pitch_rate, yaw_rate)[source]#
Sets the chassis’s linear and angular velocities, including both translational and rotational components.
- Parameters:
- vxfloat
The linear velocity along the x-axis.
- vyfloat
The linear velocity along the y-axis.
- vzfloat
The linear velocity along the z-axis.
- roll_ratefloat
The angular velocity around the x-axis (roll).
- pitch_ratefloat
The angular velocity around the y-axis (pitch).
- yaw_ratefloat
The angular velocity around the z-axis (yaw).
Suspension#
Suspension Class#
The SimpleSuspension class represents the properties of a suspension system in a vehicle model. This class models the basic dynamics of the suspension, including the stiffness and damping characteristics.
- class pymycar.Vehicle.suspension.SimpleSuspension(stiffness=None, damper=None)[source]#
Bases:
objectRepresents a simple suspension system with basic properties: stiffness and damping.
- Attributes:
- stiffnessfloat
The stiffness of the suspension in N/m. This value defines how much force the suspension applies to resist compression or extension.
- damperfloat
The damping coefficient in Ns/m. This value defines the resistance the suspension provides against motion, simulating viscous friction.
Methods
__init__(stiffness, damper)
Initializes the suspension system with the specified stiffness and damping values.
save_log_info(logger, name=”Suspension”)
Logs the suspension parameters in a tabular format using the provided logger.
- save_log_info(logger, name='Suspension')[source]#
Logs the suspension parameters in a tabular format using the provided logger.
- Parameters:
- loggerlogging.Logger
The logger instance that will be used to log the suspension details.
- namestr, optional
Custom name for the suspension system (default: “Suspension”).
Wheel#
Wheel Class#
The Wheel class represents the properties and dynamics of a single wheel in a vehicle model. This includes physical parameters such as mass, stiffness, and adherence properties, as well as the wheel’s position and orientation in 3D space.
- class pymycar.Vehicle.wheel.Wheel(mass=None, spin_inertia=None, nominal_radius=None, radial_stiffness=None, radial_damping=None, nominal_vertical_load=None, max_longitudinal_adherence=None, max_lateral_adherence=None, sidelsip_stiffness=None, longitudinal_stiffness=None)[source]#
Bases:
objectRepresents a single wheel in the vehicle model with its physical and dynamic properties.
- Attributes:
- massfloat
Mass of the wheel in kilograms.
- spin_inertiafloat
Moment of inertia for spinning motion in kg·m².
- nominal_radiusfloat
Nominal radius of the wheel in meters.
- radial_stiffnessfloat
Radial stiffness of the wheel in N/m.
- radial_dampingfloat
Radial damping coefficient of the wheel in Ns/m.
- nominal_vertical_loadfloat
Nominal vertical load supported by the wheel in N.
- max_longitudinal_adherencefloat
Maximum longitudinal adherence coefficient.
- max_lateral_adherencefloat
Maximum lateral adherence coefficient.
- sidelsip_stiffnessfloat
Side-slip stiffness in N/deg.
- longitudinal_stiffnessfloat
Longitudinal stiffness in N/deg.
- xfloat
X-coordinate position of the wheel.
- yfloat
Y-coordinate position of the wheel.
- zfloat
Z-coordinate position of the wheel.
- camberfloat
Camber angle of the wheel in degrees.
- toefloat
Toe angle of the wheel in degrees.
- side_viewfloat
Side view tilt angle of the wheel in degrees.
Methods
__init__(mass, spin_inertia, nominal_radius, radial_stiffness, radial_damping, nominal_vertical_load, max_longitudinal_adherence, max_lateral_adherence, sidelsip_stiffness, longitudinal_stiffness)
Initializes the Wheel object with provided or default parameters.
save_log_info(logger, name=”Wheel”)
Logs the wheel’s parameters in a tabular format.