Chapter 17 Around Mode

In the Around Mode, the vehicle consistently orients itself around a fixed central point using the ultrasonic module as a reference, maintaining a constant speed for circular motion. Users can modify the car’s orbital radius and direction via Freenove APP, with adjustable radius settings from 0 to 100 centimeters.

Sketch

Open “Sketch_15.1_Around_car” folder in “Freenove_Omni_Wheel_Car_Kit_for_Raspberry_Pi_Pico\Three-Wheel\Sketches” and then double-click “Sketch_15.1_Around_car.ino”.

../../../_images/Chapter17_03.png

Code

Sketch_15.1_Around_car.ino

 1bool timer_1ms_control(struct repeating_timer *t) {
 2  if (millis() % 5 == 0) {
 3    Getencoder_Data();
 4    speed_add();
 5  }
 6  if (millis() % 15 == 0) {
 7    speed_calculate();       // Find the average speed and filter the burrs
 8    Circle_Control(2,30,clockwise); 
 9  }
10  return true;
11}

Motor.cpp

 1void Circle_Control(float r, float V, float location)
 2{
 3  if(location == clockwise)
 4  {
 5    angle_circle = V / r;
 6    vx = - V * sin (90 * (PI / 180));
 7    vy = V * cos (90 * (PI / 180));
 8    v1 = -vx + angle_circle;
 9    v2 = 0.5 * vx - sqrt(3) / 2 * vy + angle_circle;
10    v3 = 0.5 * vx + sqrt(3) / 2 * vy + angle_circle;
11  }
12
13  if(location == anticlockwise)
14  {
15    angle_circle = V / r;
16    vx = - V * sin (-90 * (PI / 180));
17    vy = V * cos (-90 * (PI / 180));
18    v1 = -vx + angle_circle;
19    v2 = 0.5 * vx - sqrt(3) / 2 * vy + angle_circle;
20    v3 = 0.5 * vx + sqrt(3) / 2 * vy + angle_circle;
21  }
22  // Speed PID control
23  pid_v1 = Speed1_PID(v1,speed1);
24  pid_v2 = Speed2_PID(v2,speed2);
25  pid_v3 = Speed3_PID(v3,speed3);
26
27  Motor_direction();// Motor limiting and motor output orientation
28}

After compiling and uploading the code, place the omni-wheeled car on the ground and power it on. The omni-wheeled car will perform a uniform circular motion with a radius of 20 cm in a clockwise direction.

Code Explanation

Determine the input parameter; when the parameter is “clockwise”, the car circles clockwise, and when the parameter is “anticlockwise”, the car circles counterclockwise.

 1if(location == clockwise)
 2{
 3  angle_circle = V / r;
 4  vx = - V * sin (90 * (PI / 180));
 5  vy = V * cos (90 * (PI / 180));
 6  v1 = -vx + angle_circle;
 7  v2 = 0.5 * vx - sqrt(3) / 2 * vy + angle_circle;
 8  v3 = 0.5 * vx + sqrt(3) / 2 * vy + angle_circle;
 9}
10
11if(location == anticlockwise)
12{
13  angle_circle = V / r;
14  vx = - V * sin (-90 * (PI / 180));
15  vy = V * cos (-90 * (PI / 180));
16  v1 = -vx + angle_circle;
17  v2 = 0.5 * vx - sqrt(3) / 2 * vy + angle_circle;
18  v3 = 0.5 * vx + sqrt(3) / 2 * vy + angle_circle;
19}

About Around mode

For the connection of Bluetooth device, please refer to Introduction to the APP

Please note that the example code for this part does not involve Bluetooth.

To control the car via Bluetooth, please open “Sketch_20.1_Bluetooth_car” folder in “Three-Wheel\Sketches” and then double-click “Sketch_20.1_Bluetooth_car.ino”.

Interface Introduction

../../../_images/Chapter17_04.png

Operation Description

This button is to change the cicular direction. When it is enabled, the car circles clockwise, and disabled, it circles counterclockwise.

../../../_images/Chapter17_05.png

Input the maximum radius. If the number set is below 100, it will be 100.

../../../_images/Chapter17_06.png

Slide the bar to set the car’s circular radius. The range is from 0 to the max radius set.

../../../_images/Chapter17_07.png