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.
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
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)
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
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
Here's some code:
That's my servo function I use (yes, I like float for some odd reason)
First I call my startup function:
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:
-amehta (Andrew Mehta)
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
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)
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
Thanks, that's good to know. Especially the max/min values, I didn't think about that.
-amehta (Andrew Mehta)
@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