This example shows how to model different robot kinematics models in an environment and compare them.

**Define Mobile Robots with Kinematic Constraints**

There are a number of ways to model the kinematics of mobile robots. All dictate how the wheel velocities are related to the robot state: `[x y theta]`

, as *xy-*coordinates and a robot heading, `theta`

, in radians.

**Unicycle Kinematic Model**

The simplest way to represent mobile robot vehicle kinematics is with a unicycle model, which has a wheel speed set by a rotation about a central axle, and can pivot about its z-axis. Both the differential-drive and bicycle kinematic models reduce down to unicycle kinematics when inputs are provided as vehicle speed and vehicle heading rate and other constraints are not considered.

**Differential-Drive Kinematic Model**

The differential drive model uses a rear driving axle to control both vehicle speed and head rate. The wheels on the driving axle can spin in both directions. Since most mobile robots have some interface to the low-level wheel commands, this model will again use vehicle speed and heading rate as input to simplify the vehicle control.

To differentiate the behavior from the unicycle model, add a wheel speed velocity constraint to the differential-drive kinematic model

**Bicycle Kinematic Model**

The bicycle model treats the robot as a car-like model with two axles: a rear driving axle, and a front axle that turns about the z-axis. The bicycle model works under the assumption that wheels on each axle can be modeled as a single, centered wheel, and that the front wheel heading can be directly set, like a bicycle.

**Other Models**

The Ackermann kinematic model is a modified car-like model that assumes Ackermann steering. In most car-like vehicles, the front wheels do not turn about the same axis, but instead turn on slightly different axes to ensure that they ride on concentric circles about the center of the vehicle's turn. This difference in turning angle is called Ackermann steering, and is typically enforced by a mechanism in actual vehicles. From a vehicle and wheel kinematics standpoint, it can be enforced by treating the steering angle as a rate input.

**Set up Simulation Parameters**

These mobile robots will follow a set of waypoints that is designed to show some differences caused by differing kinematics.

**Create a Vehicle Controller**

The vehicles follow a set of waypoints using a Pure Pursuit controller. Given a set of waypoints, the robot current state, and some other parameters, the controller outputs vehicle speed and heading rate.

**Simulate the Models Using an ODE Solver**

The models are simulated using the `derivative`

function to update the state. This example uses an ordinary differential equation (ODE) solver to generate a solution. Another way would be to update the state using a loop, as shown in Path Following for a Differential Drive Robot.

Since the ODE solver requires all outputs to be provided as a single output, the pure pursuit controller must be wrapped in a function that outputs the linear velocity and heading angular velocity as a single output. An example helper, `exampleHelperMobileRobotController`

, is used for that purpose. The example helper also ensures that the robot stops when it is within a specified radius of the goal.

`ode45`

is called once for each type of model. The derivative function computes the state outputs with initial state set by `initPose`

. Each derivative accepts the corresponding kinematic model object, the current robot pose, and the output of the controller at that pose.

**Plot Results**

The results of the ODE solver can be easily viewed on a single plot using `plotTransforms`

to visualize the results of all trajectories at once.

The pose outputs must first be converted to indexed matrices of translations and quaternions.

Next, the set of all transforms can be plotted and viewed from the top. The paths of the unicycle, bicycle, and differential-drive robots are red, blue, and green, respectively. To simplify the plot, only show every tenth output.