Questions on B-Robot PID code - Printable Version +- JJRobots COMMUNITY (http://forums.jjrobots.com) +-- Forum: JJrobots (/forumdisplay.php?fid=1) +--- Forum: B-Robot (/forumdisplay.php?fid=2) +--- Thread: Questions on B-Robot PID code (/showthread.php?tid=876) Questions on B-Robot PID code - ckong80 - 06-14-2016 06:46 AM Hi, I hope someone that's familiar with the B-Robot PID code can help me out. Question#1 Code: ```// 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? Question#2 Code: ```// 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. RE: Questions on B-Robot PID code - ckong80 - 06-14-2016 07:46 PM any experts on this forum able to help? pls...