Differential control of the chassis movement, completely dependent on the control of the two drive wheels, the basic control method is as follows:

- Forward:Both driving wheel moving forward simultaneously
- Backward: Both driving wheel moving backward simultaneously
- Left turn: Left driving wheel speed is less than right driving wheel speed
- Right turn: Left driving wheel speed is greater than right driving wheel speed

In the actual installation, the general two drive motor just symmetrical installation, this time generally one of the motor control line of the positive and negative reverse installation, in order to achieve the above control effect,The specific connection method can be foundLesson 2: Hardware diagram。Only by understanding the corresponding kinematic model we can do precisely control, let’s start by discussing the kinematic model of the differential chassis

### 1.Kinematics model

#### 1.1 Right-handed Coordinate System

The movement of the robot must be carried out in a certain coordinate system, and ROS uses the right-hand coordinate system, so we need to first understand the right-hand coordinate system

Right hand coordinates as shown above, the right hand fist, thumb pointing to the Z axis, the index finger pointing to the X axis, the middle finger pointing to the Y axis, corresponding to our plane movement of the robot, motion control is to control its coordinates in the world XY Axis axis of the movement, Z-axis direction can be seen as still, that is, during the movement of the Z-axis direction of the line speed is always 0, from the robot coordinate system to see the Y-axis line speed is 0, but the angular velocity In other words, the angular velocity in the Z-axis direction is not zero, and the angular velocity in the XY-axis direction is zero;

### 1.2 Single drive wheel motion analysis

For a crawler-type chassis, if you simply look at the movement of a drive wheel, its Y-axis in the world coordinate system is also static, only the X-axis movement, that is, the Y-axis direction of the speed is 0

### 1.3 Analysis of Differential Chassis Motion of Double Drive Wheel

Because of the difference in the speed of the two drives, the entire chassis is turned toward the slow side, and based on this principle, we can control the speed of the two drive motors to control the steering of the entire robot. If we want to control the robot to go straight, That is, must be the speed of the two drive wheels is the same, otherwise it will turn. As shown in the figure below, when the speed of the left and right wheels YZ is 0, the right drive wheel speed is greater than the left drive wheel speed, turning from the top of the robot to the left.

Based on this principle in the robot control time, we will have two problems to be solved

- Given the robot line speed and angular velocity, how to break down the control parameters of the two drive wheels
- How to calculate the speed and angular velocity of the robot according to the speed value of the two driving wheels, and then calculate the mileage data,

### 2.Decompose the speed to the control parameters of the two drive wheels

The speed of the robot refers to the speed between two adjacent control times. Since the ROS itself is dependent on the high frequency of the transmission control command to accurately control the robot, we commonly used the control frequency is> 10hz, so fast Frequency, we can assume that the robot in such a short period of time through the arc between the two positions to replace the straight line. Based on the above assumptions, we can introduce the robot coordinate system.

Assume that the moving speed of the robot coordinate system is V and the time interval is Δt. Then the distance traveled in the robot coordinate system v * Δt,

Assuming that the trajectories of the two drive wheels are l, then the distance from the left wheel is v * Δt-l * sin (θ), and the linear velocity of the left wheel is deduced. Vl = (v * Δt – l * sin Θ)) / Δt; and the linear velocity of the right wheel is Vr = (v * Δt + l * sin (θ)) / Δt

### 3.Track deduction

#### 3.1 Push the track according to speed

Assume that the velocity of the robot coordinate system is V and the time interval is Δt. Then the distance traveled in the robot coordinate system v * Δt, then the decomposition of the world coordinate system within the x-axis and y-axis travel distance is

Δx=v*Δt*cos(θ) Δy=v*Δt*sin(θ)

The curvature of the rotation is：

Δθ=w*Δt

Then a period of time odom:

x=x+v*Δt*cos(θ) y=y+v*Δt*sin(θ) θ=θ+Δθ

The above is based on the speed of the robot in the ideal state according to the line speed and angular velocity to deduce the track, but the reality is that the robot does not necessarily follow the set speed of control, and there will be errors, this time we are more use of sensors Data to push the track, such as laser radar, depth camera, motor code plate, ultrasonic, gyroscope and other sensor data, some robots use only one of them, advanced robots are using a variety of sensor data fusion algorithm to improve the voyage deduction The accuracy of the. Here we introduce the most commonly used based on the motor code data track deduction.

#### 3.2 According to the code data to carry out the track

The code wheel gives the distance between the two drive motors in the time period of Δt, and the angle of rotation can be calculated as follows:：

sin(Δθ)=((Δxr-Δxl)/2)/l

Since Δt is very short, the distance traveled is very short, so do the following approximation

Δθ=sin(Δθ)=((Δxr-Δxl)/2)/l

The distance traveled by the entire machine is the average of the two motor travel distances (Δxl + Δxr) / 2

Then the XY axis is mapped to the world coordinate system：

Δx=cos(θ)*(Δxl+Δxr)/2 Δy=sin(θ)*(Δxl+Δxr)/2

Then a period of time odom:

x=x+cos(θ)*(Δxl+Δxr)/2 y=y+sin(θ)*(Δxl+Δxr)/2 θ=θ+Δθ Understanding the motion model, we can follow the principle of the model to control the movement of the robot.