Initial Servo Placement

13 replies [Last post]
amehta
Title: NooBot
Joined: 07/18/2011
Posts:
BotPoints: 136
User offline. Last seen 5 years 32 weeks ago.

So when I have my program start, the servos move in an undesirable place. I thought I could fix this by taking out the "enable_servos()" and manually setting the positions, but that didn't work. I was wondering if I could change the default positions the servos go to on startup, or some other way to get around this.

Thanks in advance.

-amehta (Andrew Mehta)

garrettsickles
garrettsickles's picture
Title: NooBot
Joined: 12/08/2011
Posts:
BotPoints: 52
User offline. Last seen 8 years 28 weeks ago.

By 'manually' do you mean physically or in the code using set_servo_position(...)?

By setting the position with set_servo_position(...), you should be able to avoid this problem.

Garrett Sickles
807Robotics: A Narwhal's Revenge
Youth Advisory Council
Geophysics & Computer Science

amehta
Title: NooBot
Joined: 07/18/2011
Posts:
BotPoints: 136
User offline. Last seen 5 years 32 weeks ago.

I used the "set_servo_position" (well my function for servos that includes "set_servo_position", but I don't think my function is the problem) and it went to whatever default position and then moved to the position I input.

-amehta (Andrew Mehta)

Jeremy Rand
Jeremy Rand's picture
Title: Botball Youth Advisory Council
Joined: 04/03/2009
Posts:
BotPoints: 1168
User offline. Last seen 7 years 18 weeks ago.

I've never seen set_servo_position do that. Can you post some code that demonstrates this problem?

-Jeremy Rand
Senior Programmer, Team SNARC (2012-2013), Norman Advanced (2010-2011), Norman HS (2008-2009), Norman North (2005-2007), Whittier MS (2003-2004)
2012-2013 VP of Tech, 2011 President, Botball YAC (2009-2013)
Mentor, Alcott and Whittier MS

garrettsickles
garrettsickles's picture
Title: NooBot
Joined: 12/08/2011
Posts:
BotPoints: 52
User offline. Last seen 8 years 28 weeks ago.

If you don't call get_servo_position(...), then I have no clue...

But if you do call get_servo_position(...) at the start of your function to record an initial position, the problem maybe that get_servo_position(...) returns (-1) because this servo is disabled and then your function, which i assume has something to do with servo speed, just thinks -1 is a position just like 0 to 2048. You may want to add in an if(...) statement to test this case and then devise a solution of your liking.

Garrett Sickles
807Robotics: A Narwhal's Revenge
Youth Advisory Council
Geophysics & Computer Science

amehta
Title: NooBot
Joined: 07/18/2011
Posts:
BotPoints: 136
User offline. Last seen 5 years 32 weeks ago.

Here's some code:

  1. void position_servo(float servo, float speed, float position)
  2. {
  3. float sp = get_servo_position(servo);
  4. if (sp < position)
  5. {
  6. while (sp < position)
  7. {
  8. sp = get_servo_position(servo);
  9. set_servo_position(servo, sp+speed);
  10. sleep(.1);
  11. }
  12. set_servo_position(servo, position);
  13. sleep(.1);
  14. }
  15. else if (sp > position)
  16. {
  17. while (sp > position)
  18. {
  19. sp = get_servo_position(servo);
  20. set_servo_position(servo, sp-speed);
  21. sleep(.1);
  22. }
  23. set_servo_position(servo, position);
  24. sleep(.1);
  25. }
  26. }

That's my servo function I use (yes, I like float for some odd reason)

First I call my startup function:

  1. if (CREATE_EXIST == 1)
  2. {
  3. create_connect();
  4. create_full();
  5. }
  6. set_each_analog_state(0, 0, 0, 0, 0, 0, 0, 0);
  7. clear_motor_position_counter(0);
  8. clear_motor_position_counter(1);
  9. clear_motor_position_counter(2);
  10. clear_motor_position_counter(3);
  11. while (a_button() == 0)
  12. {
  13. printf("Hold the A button to open the holder");
  14. sleep(1);
  15. cbc_display_clear();
  16. }
  17. release_fishfarm();
  18. gomotors(LEFT_MOTOR_PORT, RIGHT_MOTOR_PORT, 200, 400);
  19. printf("Hold the A button to open the holder");
  20. sleep(1);
  21. while (a_button() == 0);
  22. {
  23. printf("Hold the A button to open the holder");
  24. sleep(1);
  25. cbc_display_clear();
  26. }
  27. quickmtp(FISHFARM_RELEASER_PORT, 200, FISHFARM_RELEASER_HOLD_POSITION);
  28. sleep(4);

Then before I do the servo movements the servo spazzes out. (I'm guessing it's enabling first and then it's going to my position really fast). This is the code I used to move the servo after the startup function:
  1. position_servo(POLYP_LIFTER_PORT, 200, POLYP_LIFTER_UP_POSITION);

-amehta (Andrew Mehta)

garrettsickles
garrettsickles's picture
Title: NooBot
Joined: 12/08/2011
Posts:
BotPoints: 52
User offline. Last seen 8 years 28 weeks ago.

float sp = get_servo_position(servo);

The first time you call position_servo(...) before ever moving the servo, 'sp' is set to -1.
That could be the problem.

Garrett Sickles
807Robotics: A Narwhal's Revenge
Youth Advisory Council
Geophysics & Computer Science

amehta
Title: NooBot
Joined: 07/18/2011
Posts:
BotPoints: 136
User offline. Last seen 5 years 32 weeks ago.

Ok thanks.

It wasn't a big problem in my program, it was just something curious and might be a problem for future Botballers.

-amehta (Andrew Mehta)

Terry
Terry's picture
Title: NooBot
Joined: 06/08/2009
Posts:
BotPoints: 55
User offline. Last seen 5 years 18 weeks ago.

If anyone else is looking to encode commands to move a servo, let me record these comments, in hopes it will help.
I find the above discussion quite confusing.
1. No one said the basic constraint on a servo: to positions from 0 to 180 deg. (0 to 2048 position values)
2. If you physically mount the armature of the servo such that the range of angles it will move are not within the mechanical limits, no coding fix is possible. You must remove and physically reorient the armature.
3. After enabling the servos [enable_servos()] the next statement should set the servo being used to it desired initial position [set_servo_position(x, initial_pos)] where 'x' is the port number, and 'initial_pos' is the numeric value corresponding to the desired angle.
4. Both 'x' and 'initial_pos' integer values; floating variables have no place in servo control.
5. If you command a servo to the max or min value (0 or 2048) you are in danger of damaging the servo and/or the CBC. The hobby servos in the kits are not precision and may have physical stops at slightly smaller ranges; if so, the servos motors will overheat trying to get to an unreachable position. If this results in the servo shorting out, it could damage the controller.

History is a race, between Education and Catastrophe

amehta
Title: NooBot
Joined: 07/18/2011
Posts:
BotPoints: 136
User offline. Last seen 5 years 32 weeks ago.

Thanks, that's good to know. Especially the max/min values, I didn't think about that.

-amehta (Andrew Mehta)

Jeremy Rand
Jeremy Rand's picture
Title: Botball Youth Advisory Council
Joined: 04/03/2009
Posts:
BotPoints: 1168
User offline. Last seen 7 years 18 weeks ago.

@Terry enable_servos() should never be used on the CBCv2. Setting a servo position will automatically enable it. To disable a servo, set it to -1. enable_servos() is a historical relic from the XBC and CBCv1, which has no practical use anymore and only serves to confuse newbies.

-Jeremy Rand
Senior Programmer, Team SNARC (2012-2013), Norman Advanced (2010-2011), Norman HS (2008-2009), Norman North (2005-2007), Whittier MS (2003-2004)
2012-2013 VP of Tech, 2011 President, Botball YAC (2009-2013)
Mentor, Alcott and Whittier MS