We have previously realized the control of the car's four motors using a mobile phone, but it is still relatively complicated to make the car move.
Features of Nam Wheel
The Namu wheel car can move horizontally, rotate, or combine the two, that is, the car can be controlled by any combination of X-axis, Y-axis and rotation axis. The X-axis and Y-axis refer to the body coordinates. When not rotating, the body coordinates and the ground coordinates coincide.
Nam wheel motion control
The motion of the wheels of the Nam wheel trolley and the motion diagram of the trolley are shown in the figure below.
For example, if all four wheels roll forward, the car moves forward. The car's movement can be decomposed into three basic modes: straight, translation and rotation. All of them are achieved through the rotation of the four wheels. Therefore, we can get a mapping relationship between the car's movement mode and the wheel rotation. The relationship is as follows:
In the formula, Uw1, Uw2, Uw3, and Uw4 represent the wheel speeds of quadrants 1234 respectively, Uty represents the vertical speed of the car, Uty represents the horizontal speed, w represents the angular velocity of the car, and a and b represent the length and width between the wheels of the car.
APP control code writing
Write the control code in the APP. The APP only needs to output the control amount of the four wheels. Based on the previous mobile phone remote control motor rotation , add the linkage between the joystick and the drag bar. The joystick is used to control the vertical and horizontal movement, and the drag bar is used for steering. The main code examples are as follows.
void mecanumRun(float xSpeed, float ySpeed, float aSpeed)
{
float maxLinearSpeed=100;
float speed1 = ySpeed - xSpeed + aSpeed;
float speed2 = ySpeed + xSpeed - aSpeed;
float speed3 = ySpeed - xSpeed - aSpeed;
float speed4 = ySpeed + xSpeed + aSpeed;
float max = speed1;
if (max < speed2) max = speed2;
if (max < speed3) max = speed3;
if (max < speed4) max = speed4;
if (max > maxLinearSpeed)
{
speed1 = speed1 / max * maxLinearSpeed;
speed2 = speed2 / max * maxLinearSpeed;
speed3 = speed3 / max * maxLinearSpeed;
speed4 = speed4 / max * maxLinearSpeed;
}
mSeekBar_Wheel_1.setProgress((int)(speed1+100));
mSeekBar_Wheel_2.setProgress((int)(speed2+100));
mSeekBar_Wheel_3.setProgress((int)(speed3+100));
mSeekBar_Wheel_4.setProgress((int)(speed4+100));
}
The achieved effects are as follows.
In this way, by controlling the joystick, the speed of the four motors can be decoupled, thereby controlling the movement of the car.
question
This control seems to be able to start running directly, but in fact there are still some problems. For example, the reduction motor has a large control dead zone. Assuming the full control value is 100, it will not start to rotate below 40, but once it starts to rotate, it will decelerate to the control value of 40 and the motor will rotate.
There is another question, how to run the program as soon as the Raspberry Pi is turned on.
Source code
GitHub
Gitee