.. _vehicles: Vehicles ======== This section describes vehicle definitions, dynamics models, and control systems in MVSim. Vehicles are mobile robots or platforms that can move through the simulated world using various locomotion systems. .. contents:: :depth: 1 :local: :backlinks: none 1. Overview ------------ Vehicles in MVSim are defined through XML configuration files that specify: * **Dynamics model** - The type of locomotion (differential drive, Ackermann steering, etc.) * **Physical properties** - Mass, dimensions, wheel configurations * **Motor controllers** - How commands translate to wheel torques * **Friction models** - Ground interaction and traction characteristics * **Sensors** - Optional sensor attachments (LiDAR, cameras, IMU, etc.) * **Visual models** - 3D meshes for rendering 2. Vehicle Definition Structure -------------------------------- Basic XML Structure ~~~~~~~~~~~~~~~~~~~ Vehicles are defined using ```` tags for reusable templates, and ```` tags for specific instances: .. code-block:: xml 0 0 0 0 0 0 Common Vehicle Parameters ~~~~~~~~~~~~~~~~~~~~~~~~~ **Chassis Configuration:** .. code-block:: xml -0.4 -0.5 -0.4 0.5 0.4 0.5 0.4 -0.5 **Chassis Attributes:** * **mass** - Vehicle chassis mass in kilograms * **zmin**, **zmax** - Minimum and maximum Z coordinates for collision detection * **color** - RGB color in hex format (e.g., #FF0000) * **shape** - 2D polygon defining the chassis footprint (list of elements) * **shape_from_visual** - Automatically extract collision shape from 3D visual model **Odometry Configuration:** .. code-block:: xml Adds realistic noise to odometry by multiplying actual pose increments. Values are typically drawn from ``$f{1.0 + 0.02*randn()}`` to simulate sensor imperfections. **Visual Models:** .. code-block:: xml path/to/model.dae 0.001 0.0 0.0 0.0 0.0 0.0 90.0 3. Dynamics Models ------------------- MVSim supports several vehicle dynamics models representing different locomotion systems. Differential Drive ~~~~~~~~~~~~~~~~~~ **Class:** ``differential``, ``differential_3_wheels``, ``differential_4_wheels`` Two independently driven wheels (or sets of wheels) that control vehicle motion through differential speeds. Common in mobile robots like TurtleBot. .. code-block:: xml 5 10 1 0 100 **Wheel Parameters:** * **pos** - Position (x, y) relative to chassis center [meters] * **mass** - Wheel mass [kg] * **width** - Wheel width [meters] * **diameter** - Wheel diameter [meters] **Kinematics:** The vehicle angular velocity and linear velocity are computed from wheel speeds: .. math:: \omega_{veh} = \frac{\omega_r \cdot R_r - \omega_l \cdot R_l}{y_r - y_l} .. math:: v_x = \omega_l \cdot R_l + \omega \cdot y_l where :math:`\omega_i` is wheel angular velocity, :math:`R_i` is wheel radius, and :math:`y_i` is the lateral position of wheel :math:`i`. Ackermann Steering ~~~~~~~~~~~~~~~~~~ **Class:** ``ackermann`` Four-wheeled vehicle with front-wheel steering geometry. The two front wheels turn to steer the vehicle, while rear wheels remain parallel to the chassis axis. .. code-block:: xml 1.3 2.0 30.0 1500 50 20 0 600 **Ackermann-Specific Parameters:** * **f_wheels_x** - Distance from rear to front axle (wheelbase) [meters] * **f_wheels_d** - Distance between front wheel centers (track width) [meters] * **max_steer_ang_deg** - Maximum steering angle for each front wheel [degrees] **Steering Geometry:** The Ackermann geometry ensures wheels trace correct turning circles: .. math:: \alpha_{outer} = \arctan\left(\cot(|\alpha|) + \frac{w}{2l}\right)^{-1} .. math:: \alpha_{inner} = \arctan\left(\cot(|\alpha|) - \frac{w}{2l}\right)^{-1} where :math:`\alpha` is the desired steering angle, :math:`w` is track width, and :math:`l` is wheelbase. Ackermann with Drivetrain ~~~~~~~~~~~~~~~~~~~~~~~~~~ **Class:** ``ackermann_drivetrain`` Enhanced Ackermann model with realistic powertrain simulation including differentials. A single "motor" output is distributed to wheels through differential mechanisms. .. code-block:: xml 0.5 1.5 0.5 1.5 0.5 1.5 **Drivetrain Types:** * ``open_front`` - Front-wheel drive with open differential * ``open_rear`` - Rear-wheel drive with open differential * ``open_4wd`` - All-wheel drive with open differentials * ``torsen_front`` - Front-wheel drive with Torsen limited-slip differential * ``torsen_rear`` - Rear-wheel drive with Torsen limited-slip differential * ``torsen_4wd`` - All-wheel drive with Torsen limited-slip differentials **Differential Parameters:** * **xxx_split** - Torque distribution ratio (0.5 = 50/50 split) * **xxx_bias** - Torsen bias ratio (how much more torque can go to wheel with traction) **Open Differential:** Torque is split according to the split coefficients: .. math:: \tau_{FL} = \tau_{motor} \cdot K_{s,f} \cdot K_{s,frl} .. math:: \tau_{FR} = \tau_{motor} \cdot K_{s,f} \cdot (1 - K_{s,frl}) **Torsen Differential:** Self-locking behavior based on wheel speed differences. The bias ratio :math:`b` (default 1.5) determines locking strength: .. math:: \delta_{lock} = \omega_{max} - b \cdot \omega_{min} Torque distribution changes dynamically to favor the wheel with more traction. 4. Motor Controllers ---------------------- Controllers translate high-level commands (velocity, steering) into wheel torques. Raw Controllers ~~~~~~~~~~~~~~~ **Class:** ``raw`` (differential), ``front_steer`` (Ackermann) Direct control of wheel torques and steering angles. User provides: * Wheel torques directly * Steering angle (Ackermann only) .. code-block:: xml Twist PID Controllers ~~~~~~~~~~~~~~~~~~~~~ **Class:** ``twist_pid`` (differential), ``twist_front_steer_pid`` (Ackermann) PID control of linear and angular velocities. Automatically computes required wheel torques to achieve desired twist commands. .. code-block:: xml 5 10 1 0 0.0 0 100 **For Differential Drive:** Desired wheel velocities are computed from commanded twist :math:`(\nu, \omega)`: .. math:: v_l = \nu - \frac{\omega \cdot w}{2} .. math:: v_r = \nu + \frac{\omega \cdot w}{2} where :math:`w` is the lateral distance between wheels. **For Ackermann:** Steering angle is computed from turn radius, and PID controls wheel torques to achieve desired speed while accounting for different wheel speeds in turns. Ideal Controllers ~~~~~~~~~~~~~~~~~ **Class:** ``twist_ideal`` Perfect velocity control without dynamics. Instantly achieves commanded velocities. Useful for testing high-level algorithms without worrying about low-level control. .. code-block:: xml 5. Friction Models ------------------- Friction models simulate tire-ground interaction, determining forces and wheel slip. .. note:: The ``mu`` and ``C_rr`` parameters of any friction model can be overridden spatially using ``PropertyRegion`` world elements with the property names ``friction_mu`` and ``friction_C_rr``. See :ref:`physics` for details. Default Friction ~~~~~~~~~~~~~~~~ **Class:** ``default`` Basic friction model with Coulomb friction and viscous damping. Suitable for most indoor robotics applications. .. code-block:: xml 0.8 1.0 0.01 **Model Equations:** Maximum friction force: .. math:: F_{max} = \mu \cdot m_{wheel} \cdot g Lateral friction (prevents side slip): .. math:: F_{lat} = \text{clamp}\left(\frac{-v_y \cdot m}{\Delta t}, -F_{max}, F_{max}\right) Longitudinal friction (accelerates/decelerates wheel): .. math:: F_{lon} = \frac{\tau_{motor} - I_{yy} \alpha_{desired} - C_{damp} \omega - T_rr}{R} Ward-Iagnemma Friction ~~~~~~~~~~~~~~~~~~~~~~ **Class:** ``wardiagnemma`` Advanced model with rolling resistance based on Ward & Iagnemma (2008) :cite:`ward2008dynamic`. Includes velocity-dependent rolling resistance for more realistic off-road simulation. .. code-block:: xml 0.7 10 50 0.0075 0.02 0.0 **Rolling Resistance:** .. math:: F_{rr} = -\text{sign}(v_x) \cdot N \cdot \left(R_1 (1 - e^{-A_{roll}|v_x|}) + R_2|v_x|\right) This force opposes motion and depends on normal force :math:`N` and velocity :math:`v_x`. Ellipse Curve Method ~~~~~~~~~~~~~~~~~~~~~ **Class:** ``ellipse`` Physics-based tire model using elliptical friction curves. Models slip angle and slip ratio effects, suitable for vehicle dynamics research. .. code-block:: xml 0.05 0.01 8.5 0.1 0.5 7.5 0.1 0.5 **Slip Angle** :math:`\alpha` - Angle between wheel heading and velocity direction **Slip Ratio** :math:`s`: .. math:: s = \frac{v_{wheel} - v_x}{|v_{wheel}|} **Friction Forces:** .. math:: F_x = F_z C_s \text{sat}(s, s_s) \sqrt{1 - C_{s\alpha} \left(\frac{\text{sat}(\alpha, \alpha_s)}{\alpha_s}\right)^2} .. math:: F_y = F_z C_\alpha \text{sat}(\alpha, \alpha_s) \sqrt{1 - C_{\alpha s} \left(\frac{\text{sat}(s, s_s)}{s_s}\right)^2} 6. Predefined Vehicle Classes ------------------------------- The following predefined vehicle classes are available in the ``definitions/`` directory. TurtleBot3 Burger ~~~~~~~~~~~~~~~~~ **File:** ``turtlebot3_burger.vehicle.xml`` Small differential-drive educational robot. **Specifications:** * Dynamics: Differential drive * Mass: 1.0 kg (chassis), 0.1 kg (each wheel) * Wheel diameter: 0.066 m * Wheel separation: 0.16 m * Default sensors: RPLidar A2, camera, IMU Jackal UGV ~~~~~~~~~~ **File:** ``jackal.vehicle.xml`` Four-wheel differential-drive robot for outdoor applications. **Specifications:** * Dynamics: Differential (4 wheels) * Mass: 10.0 kg (chassis) * Wheel diameter: 0.20 m * Wheelbase: 0.26 m, Track width: 0.32 m * Default sensors: 2D LiDAR, 3D LiDAR, camera Small Robot ~~~~~~~~~~~ **File:** ``small_robot.vehicle.xml`` Generic small differential-drive robot template. **Specifications:** * Dynamics: Differential drive * Mass: 15.0 kg (chassis), 4.0 kg (each wheel) * Wheel diameter: 0.40 m * Wheel separation: 1.0 m Ackermann Car ~~~~~~~~~~~~~ **File:** ``ackermann.vehicle.xml`` Generic car-like vehicle with Ackermann steering. **Specifications:** * Dynamics: Ackermann steering * Mass: 800.0 kg * Wheel diameter: 0.62 m * Wheelbase: 1.3 m, Track width: 2.0 m * Max steering: ±30° * Drivetrain: Torsen 4WD Pickup Truck ~~~~~~~~~~~~ **File:** ``pickup.vehicle.xml`` Large Ackermann vehicle representing a pickup truck. **Specifications:** * Dynamics: Ackermann steering * Mass: 2000.0 kg * Wheel diameter: 0.8 m * Wheelbase: 3.5 m * Max steering: ±40° AgriCobiot2 ~~~~~~~~~~~ **File:** ``agricobiot2.vehicle.xml`` Agricultural robot with custom 3D model and Ackermann drivetrain. **Specifications:** * Dynamics: Ackermann with drivetrain * Mass: 97.0 kg * Wheel diameter: 0.406 m * Wheelbase: 0.62 m * Open rear-wheel drive 7. Creating Custom Vehicles ---------------------------- Step 1: Define Vehicle Class ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a new XML file in the ``definitions/`` directory: .. code-block:: xml -0.3 -0.3 -0.3 0.3 0.3 0.3 0.3 -0.3 10 5 2 50 0.8 0.5 Step 2: Instantiate in World File ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: xml 0 0 0 Step 3: Add Sensors (Optional) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: xml 0 0 0 8. Advanced Features --------------------- Linked Visual Objects ~~~~~~~~~~~~~~~~~~~~~ For Ackermann vehicles with visible steering mechanisms: .. code-block:: xml The ``linked_yaw`` attribute names a visual object whose yaw angle will track the wheel's steering angle, offset by ``linked_yaw_offset_deg``. Shape from Visual Model ~~~~~~~~~~~~~~~~~~~~~~~ Automatically extract collision shape from 3D mesh: .. code-block:: xml This computes the chassis polygon and height from the bounding box of visual models. Multiple Visual Models ~~~~~~~~~~~~~~~~~~~~~~ Add multiple 3D models to a vehicle: .. code-block:: xml base models/base.dae sensor_mast models/mast.dae 0.5 9. Debugging and Logging ------------------------- Enable vehicle logging for debugging: .. code-block:: xml /path/to/logs/ This creates CSV files: * ``mvsim__pose.csv`` - Vehicle pose and velocity over time * ``mvsim__wheel_.csv`` - Per-wheel forces, torques, and velocities 10. ROS 2 Topics ----------------- MVSim publishes the following ROS 2 topics for each vehicle. Topic names are prefixed with the vehicle name when multiple vehicles exist in the simulation, or published directly when only one vehicle is present. Standard Vehicle Topics ~~~~~~~~~~~~~~~~~~~~~~~ Always published for each vehicle: * ``/odom`` (nav_msgs/Odometry) - Odometry computed from wheel encoders with configurable noise * ``/base_pose_ground_truth`` (nav_msgs/Odometry) - Perfect ground truth pose and velocity * ``/collision`` (std_msgs/Bool) - Collision detection flag, true when vehicle collides * ``/chassis_markers`` (visualization_msgs/MarkerArray) - RViz markers for chassis and wheel visualization * ``/chassis_polygon`` (geometry_msgs/Polygon) - 2D footprint polygon of the vehicle * ``/tf`` (tf2_msgs/TFMessage) - Dynamic transforms (odom→base_link, sensor frames) * ``/tf_static`` (tf2_msgs/TFMessage) - Static transforms (base_link→base_footprint) Fake Localization Topics ~~~~~~~~~~~~~~~~~~~~~~~~~ Published when ``do_fake_localization`` parameter is enabled: * ``/amcl_pose`` (geometry_msgs/PoseWithCovarianceStamped) - Fake AMCL localization output * ``/particlecloud`` (geometry_msgs/PoseArray) - Single-particle fake particle filter Sensor Topics ~~~~~~~~~~~~~ Published dynamically based on sensors attached to the vehicle: **2D LiDAR:** * ``/`` (sensor_msgs/LaserScan) - 2D laser scan data **3D LiDAR:** * ``/_points`` (sensor_msgs/PointCloud2) - 3D point cloud (XYZ, XYZRGB, XYZIRT) **Camera:** * ``//image_raw`` (sensor_msgs/Image) - Camera image * ``//camera_info`` (sensor_msgs/CameraInfo) - Camera calibration parameters **Depth Camera (RGBD):** * ``/_image`` (sensor_msgs/Image) - RGB image * ``/_image_camera_info`` (sensor_msgs/CameraInfo) - RGB camera calibration * ``/_depth`` (sensor_msgs/Image) - Depth image (16UC1, values in millimeters) * ``/_depth_camera_info`` (sensor_msgs/CameraInfo) - Depth camera calibration * ``/_points`` (sensor_msgs/PointCloud2) - Point cloud (XYZ or XYZRGB) **IMU:** * ``/`` (sensor_msgs/Imu) - Inertial measurement data **GNSS/GPS:** * ``/`` (sensor_msgs/NavSatFix) - GPS position with optional covariance Coordinate Frames ~~~~~~~~~~~~~~~~~ MVSim uses the REP-105 standard coordinate frames: * ``map`` - World fixed frame (only with fake_localization) * ``odom`` - Odometry frame, drift-free over short periods * ``base_link`` - Robot body frame at the center of rotation * ``base_footprint`` - Projection of base_link onto the ground plane * ```` - Individual sensor frames (camera, lidar, etc.) CSV Logger → ROS 2 publishing ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If publishing log topics is enabled via ``publish_log_topics:=True``: .. code-block:: bash ros2 launch mvsim launch_world.launch.py \ world_file:=my.world.xml \ publish_log_topics:=True these topics will be created (per vehicle, lazily on first data): * ``/log/pose/Timestamp`` (Float64) * ``/log/pose/q0x`` (Float64) * ``/log/pose/q1y`` (Float64) * ``/log/pose/dqx`` (Float64) ... * ``/log/wheel_1/torque`` (Float64) * ``/log/wheel_1/friction_x`` (Float64) ... 11. ROS 2 Subscribed Topics ---------------------------- Command Topics ~~~~~~~~~~~~~~ Each vehicle subscribes to: * ``/cmd_vel`` (geometry_msgs/Twist) - Velocity commands (linear.x, linear.y, angular.z) The command is processed by the vehicle's controller (twist_pid, twist_ideal, etc.) and converted to wheel torques. Commands older than 1 second are automatically discarded for safety.