Full Version: Questions on B-Robot PID code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I hope someone that's familiar with the B-Robot PID code can help me out.


// Estimated_Speed = angular_velocity_of_stepper_motors(combined) - angular_velocity_of_robot(angle measured by IMU)
1   actual_robot_speed_Old = actual_robot_speed;
2   actual_robot_speed = (speed_M1 + speed_M2) / 2; // Positive: forward

3   int16_t angular_velocity = (angle_adjusted - angle_adjusted_Old) * 90.0; // 90 is an empirical extracted factor to adjust for real units
4   int16_t estimated_speed = -actual_robot_speed_Old - angular_velocity;     // We use robot_speed(t-1) or (t-2) to compensate the delay

In the third line, why is the angular_velocity not = (angle_adjusted - angle_adjusted_Old)/ looptime but multiplied by 90 instead?


// PI controller implementation (Proportional, integral). DT is in miliseconds
    float speedPIControl(float DT, float input, float setPoint,  float Kp, float Ki)
1      float error;
2      float output;

3     error = setPoint - input;
4     PID_errorSum += constrain(error, -ITERM_MAX_ERROR, ITERM_MAX_ERROR);
5     PID_errorSum = constrain(PID_errorSum, -ITERM_MAX, ITERM_MAX);

6     //Serial.println(PID_errorSum);

7     output = Kp * error + Ki * PID_errorSum * DT * 0.001; // DT is in miliseconds...
8     return (output);

From what I have read, the inputs to the PI controller are: (1)Velocity setpoint and (2)Estimated velocity, and the output should be the desired tilt angle for the robot to maintain its balance.

Looking at line 7 of the code snippet, I cannot understand why the return value would turn out to be the desire tilt angle. Can someone help me out here?

Thank you.
any experts on this forum able to help? pls...
Reference URL's