motor PID control

2 replies [Last post]
ahfagg
Title: NooBot
Joined: 01/16/2013
Posts:
BotPoints: 13
User offline. Last seen 8 years 34 weeks ago.

In playing with mrp (move relative position) and get_motor_done, we discovered that calls to get_motor_done immediately following mrp will return 1 (as in, completed). Presumably this is due to the thread responsible for handling the PID control not having a chance update the motor state before get_motor_done is called. The current work-around is to msleep following the mrp call (30ms seems to work fine). Code example below...

Also - with 1.9.1 of the kernel, motor 1 is now working under PID control.

Andrew Fagg

------------------------------------------------------------------------------------------------------------------------------

  1. #define MOTOR 1
  2.  
  3. int main()
  4. {
  5. // Reset the position counter to zero
  6. clear_motor_position_counter(MOTOR);
  7. printf("Start: %d %d\n", get_motor_done(MOTOR), get_motor_position_counter(MOTOR));
  8.  
  9. // Wait for button B to be pressed
  10. while(!b_button()){};
  11.  
  12. // Initiate a move by 2000
  13. mrp(MOTOR, 400, (long) 2000);
  14.  
  15. // Need to sleep before get_motor_done()
  16. msleep(30);
  17.  
  18. // While no button has been pressed and the motor is not done
  19. while((!a_button()) && (!get_motor_done(MOTOR))) {
  20. // Print the state of the motor
  21. printf("Progress: %d %d\n", get_motor_done(MOTOR), get_motor_position_counter(MOTOR));
  22. msleep(1000);
  23. }
  24. printf("Done... %d %d\n", get_motor_done(MOTOR), get_motor_position_counter(MOTOR));
  25. }

Beta
Beta's picture
Title: The Magnificent
Joined: 02/24/2012
Posts:
BotPoints: 266
User offline. Last seen 8 years 34 weeks ago.

This is precisely the case. block_motor_done() has a similar msleep to avoid this issue. I will evaluate possible fixes for get_motor_done in the upcoming 1.92. Thank you for the detailed report!

Braden McDorman

Developer of the KIPR Link, KISS IDE, KIPR's 2D Simulator, and CBCJVM.

Reach me at bmcdorman(cat)kipr(dog)org where (cat)=@ and (dog)=. if you need assistance of any kind.

Beta
Beta's picture
Title: The Magnificent
Joined: 02/24/2012
Posts:
BotPoints: 266
User offline. Last seen 8 years 34 weeks ago.

This has been fixed in 1.9.2.

Braden McDorman

Developer of the KIPR Link, KISS IDE, KIPR's 2D Simulator, and CBCJVM.

Reach me at bmcdorman(cat)kipr(dog)org where (cat)=@ and (dog)=. if you need assistance of any kind.