mrpt.kinematics

mrpt.kinematics — Vehicle kinematic models and simulators.

Provides:
  • CVehicleVelCmd : Base class of velocity commands

  • CVehicleVelCmd_DiffDriven : Velocity command for differential-drive robots

  • CVehicleVelCmd_Holo : Velocity command for holonomic robots

  • CVehicleSimulVirtualBase : Abstract base for vehicle simulators

  • CVehicleSimul_DiffDriven : Differential-drive robot simulator

  • CVehicleSimul_Holo : Holonomic robot simulator

Example — simulate a diff-drive robot:

import mrpt.kinematics as kin
import mrpt.math

robot = kin.CVehicleSimul_DiffDriven()
robot.movementCommand(lin_vel=0.5, ang_vel=0.1)
for _ in range(100):
    robot.simulateOneTimeStep(dt=0.01)
pose = robot.getCurrentGTPose()
print(f"Pose: ({pose.x:.3f}, {pose.y:.3f}, {pose.phi:.3f})")

Package Contents

class mrpt.kinematics.CVehicleSimulVirtualBase

C++ API: class mrpt::kinematics::CVehicleSimulVirtualBase

Base class of the 2D robot kinematic simulators, including odometry errors.

getCurrentGTPose() → mrpt.math.TPose2D

Get current ground-truth pose (x, y, phi)

getCurrentGTVel() → mrpt.math.TTwist2D

Returns the ground truth velocity (vx, vy, omega) in world coordinates. With odometry errors enabled, this is the noise-free commanded velocity.

getCurrentGTVelLocal() → mrpt.math.TTwist2D

Returns the ground truth velocity (vx, vy, omega) in the robot local frame.

getCurrentOdometricPose() → mrpt.math.TPose2D

Get current odometric (noisy) pose (x, y, phi)

getCurrentOdometricVel() → mrpt.math.TTwist2D

Returns the odometric velocity (vx, vy, omega) in the odometry frame.

getCurrentOdometricVelLocal() → mrpt.math.TTwist2D

Returns the odometric velocity (vx, vy, omega) in the robot local frame.

getTime() → float

Returns the current simulation time (seconds).

getVelCmdType() → CVehicleVelCmd

Returns an empty velocity command of the type this simulator accepts.

resetStatus() → None

Resets the poses, velocities and pending commands, but not the simulation time.

resetTime() → None

Resets the simulation time to zero.

sendVelCmd(cmd_vel: CVehicleVelCmd) → None

Sends a velocity command, whose type must match the simulator: CVehicleVelCmd_DiffDriven or CVehicleVelCmd_Holo.

setCurrentGTPose(pose: mrpt.math.TPose2D) → None

Brute-force move robot to target coordinates (“teleport”)

setCurrentOdometricPose(pose: mrpt.math.TPose2D) → None

Brute-force overwrite robot odometry.

setOdometryErrors(enabled: bool, Ax_err_bias: float = 0.001, Ax_err_std: float = 0.01, Ay_err_bias: float = 0.001, Ay_err_std: float = 0.01, Aphi_err_bias: float = 1.7453292519943296e-05, Aphi_err_std: float = 0.00017453292519943296) → None

Enables or disables odometry errors: relative factors applied to the displacement in the vehicle frame (x forward, y left, phi heading). Bias values are relative errors; std values are 1-sigma relative errors accumulated over 1 second of motion.

simulateOneTimeStep(dt: float) → None

Advance simulation by dt seconds

class mrpt.kinematics.CVehicleSimul_DiffDriven

C++ API: class mrpt::kinematics::CVehicleSimul_DiffDriven

Bases: CVehicleSimulVirtualBase

Simulates the kinematics of a differential-driven planar mobile robot/vehicle, including odometry errors and dynamics limitations.

getV() → float

Returns the current linear velocity (m/s).

getW() → float

Returns the current angular velocity (rad/s).

movementCommand(lin_vel: float, ang_vel: float) → None

Set velocity command: linear (m/s) and angular (rad/s)

setDelayModelParams(TAU_delay_sec: float = 1.8, CMD_delay_sec: float = 0.0) → None

Sets the dynamics model: velocities follow commands with a first order response of time constant TAU_delay_sec, after a pure delay of CMD_delay_sec (0, 0: immediate).

class mrpt.kinematics.CVehicleSimul_Holo

C++ API: class mrpt::kinematics::CVehicleSimul_Holo

Bases: CVehicleSimulVirtualBase

Kinematic simulator of a holonomic 2D robot capable of moving in any direction, with “blended” velocity profiles.

sendVelRampCmd(vel: float, dir: float, ramp_time: float, rot_speed: float) → None

Send a velocity ramp command to the holonomic robot

class mrpt.kinematics.CVehicleVelCmd

C++ API: class mrpt::kinematics::CVehicleVelCmd

Bases: mrpt.serialization.CSerializable

Base class of the velocity commands of the kinematic models (and of real robots).

asString() → str

Returns a human-readable description of the command.

getVelCmdDescription(index: int) → str

Returns a description of the index-th component of the velocity command.

getVelCmdElement(index: int) → float

Returns the index-th component of the velocity command.

getVelCmdLength() → int

Returns the number of components of the velocity command.

setVelCmdElement(index: int, value: float) → None

Sets the index-th component of the velocity command.

class mrpt.kinematics.CVehicleVelCmd_DiffDriven

C++ API: class mrpt::kinematics::CVehicleVelCmd_DiffDriven

Bases: CVehicleVelCmd

Kinematic model for Ackermann-like or differential-driven vehicles.

property ang_vel: float

Angular velocity (rad/s)

property lin_vel: float

Linear velocity (m/s)

isStopCmd() → bool

Returns true if the command means “do not move” / “stop”.

setToStop() → None

Set to a command that means “do not move” / “stop”.

class mrpt.kinematics.CVehicleVelCmd_Holo

C++ API: class mrpt::kinematics::CVehicleVelCmd_Holo

CVehicleVelCmd_Holo(vel: float, dir_local: float, ramp_time: float, rot_speed: float)

Bases: CVehicleVelCmd

Velocity command for holonomic robots: speed, direction, rotational speed and ramp time.

property dir_local: float

Direction relative to robot heading (radians)

property ramp_time: float

Blending time (seconds)

property rot_speed: float

Rotational speed for heading correction (rad/s)

property vel: float

Linear speed (m/s)

isStopCmd() → bool

Returns true if the command means “do not move” / “stop”.

setToStop() → None

Set to a command that means “do not move” / “stop”.