Log in

View Full Version : Problems running servos


smigs
30-01-2012, 14:29
Hi everyone,

I am a coach on Team 3373 out of Warrenton, VA. Recently, our programming team was writing some code for a generic servo (I didn't think it was necessary to label the part number) in order to make sure we know how to write the code.

Displaying only the relevant portions, we defined a joystick (in Module 1) and a servo instance. Then we initialized the servo instance. We physically connected it to Module 2, Port/Channel 9. Afterwards, we noted because the joystick GetRawAxis function assumes values from [-1,1] and the Servo Set function assumes values from [0,1] we did a little algebra on the Servo Set argument.

Lastly, I printed to the driver station the value of the Servo Set argument and I saw it change as I moved the Xbox joystick. HOWEVER, the servo itself does not move.

We do have other code written (not displayed) which moves a motor and gets camera feed etc. which all work fine. But for whatever reason we cannot get the Servo to work. There are a limited number of functions for the Servo class so between trying different things and looking on Google, we just need a fresh pair of eyes. Can anyone make any suggestions? The code compiles when we run it. We obtained the skeleton of it from the Simple Robot Template in Windriver.

Many thanks,
Brian

#####BEGIN CODE #####

#include “WPILib.h”
class RobotDemo : public SimpleRobot {

Joystick Xbox;
Servo Elevation;

public: RobotDemo()
Xbox(1),
Elevation(2,9)

{
/* GetWatchdog().SetEnabled(false); */
}

void Autonomous() {
/* commented out code */
}


void OperatorControl() {
while (IsOperatorControl())
{
Elevation.Set((Xbox.GetRawAxis(5)+1)/2);
}
}

};

START_ROBOT_CLASS(RobotDemo);

#####END CODE #####

Cecil
30-01-2012, 14:35
I'm not fluent in that language at all, but the first thing I would check is to see if you have a jumper on the pins next to the servo output. Without that jumper, the servo will not get power to move at all.

omalleyj
30-01-2012, 15:19
I'm not fluent in that language at all, but the first thing I would check is to see if you have a jumper on the pins next to the servo output. Without that jumper, the servo will not get power to move at all.

I would just add to that: make sure the DSC is getting power, showing the 6V indicator lit, not just the 5V.

Codewise:
Try hardcoding a value and verify that it is (or isn't) hardware. If the hardcoded value works and the code doesn't.
Good luck!

slijin
30-01-2012, 15:42
One possible problem is that your servo is unusual and doesn't operate on the conventional signal range. We've encountered this problem before with Parallax servos. As a reference (I'm not sure about the actual DS output), since Hitec servos are the brand that FIRST recommends,

All Hitec servos require 3-5V peak to peak square wave pulse. Pulse duration is from 0.9mS to 2.1mS with 1.5mS as center. The pulse refreshes at 50Hz (20mS).

feverittm
30-01-2012, 15:49
Did you remember to connect the 6V jumper for Servo power on the Digital Sidecar?

smigs
30-01-2012, 21:20
Hi everyone,

Thank you so much for your inputs (no pun intended ;)

One thought I did have was to make sure the port we are using has a recorded 6 V difference on the DSC which it does. I also did hardcode a value in for the servo and no response. The DSC is also getting power since we have other hardware hooked into it and it is functioning properly with the correct C++ code.

I never thought about the servo not operating in the conventional signal range so that is something to look at. I am new to FRC so I am still learning where things go etc., but I do know some programming so I feel reasonably confident that the code is correct, especially since the analogous code for the motors work fine.

For feverittm: If the 6V jumper were not present, what would happen? In other words, would there still be a voltage difference across the leads?

Thanks everyone for your quick replies.

Tom Line
30-01-2012, 21:46
The jumper is what applies the 5 Volt power to the hot pin on the pwm / servo outputs. Without it, the servos get no power.

Joe Ross
30-01-2012, 22:27
In your code, change the digital module to 1, instead of 2.

theprgramerdude
30-01-2012, 22:58
What Joe said. Module numbers =/= Slot numbers, it's a semantics change this year that chokes people up who haven't followed everything. Once that changes, it should work fine.

smigs
31-01-2012, 23:18
Changing the module to 1 did work!! Thank you so much for the help!!