? programming servos

we are having a heck of a time progrmming the servos for the camera.

We are trying to make the X-axis servo turn with the X-axis of the joystick and the Y-axis servo turn with the Y-axis of the joystick.

We have no clue. we tried some code that tests the max and min angles but what happened is a watchdog error saying it was not fed. We are perplexed at this stuff.

Does anyone have the capabilities to move the camera with servos. and would yo be willing to paste it for us to look at?

If you’re having problems with the watchdog, remember to feed it really often.

If your code cannot do this comfortably (see: Constant 'wait’s), then do


in your teleoperated code. (If the Watchdog is not fed, it keeps most things from running on your robot. :wink: )

Please note that disabling it this takes a large layer of safety away from your robot, so try to keep your Watchdog enabled as often as you can…

Good luck getting Servos to work. :smiley:

First, you need to make sure you actually have your servos connected properly and that they actually work, before trying to do something more complex with them. Heres an example MyRobot.cpp that will help you do that (I’ve compiled this, but haven’t tested it – but it should work just fine).

#include "WPILib.h"

// define the slot numbers so we don't get confused and 
// use 1 and 2 instead of 4 and 6
#define DIGITAL_SLOT_1 4
#define DIGITAL_SLOT_2 6

// PWM channel your servo is in

class RobotDemo : public SimpleRobot
	Servo servo;
	Joystick stick;


	void OperatorControl(void)
		while (IsOperatorControl())
			// control the servo with a joystick
			servo.Set( stick.GetDirectionDegrees() );
			Wait(0.005);				// wait for a motor update time


I don’t know why you are getting watchdog timer errors and can’t tell without seeing your code. However, there are a few things about servos that you should be aware of. One, Make sure that there is a jumper on the digital sidecar associated with the PWM output that is driving your servo. That supplies power to the servo and it won’t work without the jumper. The jumper goes right next to the PWM output. Two, the servo class takes a value between 0.0 and 1.0, not the -1.0 to 1.0 that you get from your joystick. You should add 1.0 to your joystick value and then divide by 2.

Ahh thanks for the sample code. The servo is fully functioning. the tips for adjusting the servo values helped too thanks. Just onbe step at a time for us.

If someone doesnt mind responding, how do we deal with analog inputs?

We are trying to use a potentiometer.

to declare one is fairly easy,
AnalogChannel *pot;
pot=new AnalogChannel(<channel>);

then to get the voltage from it:

check out the c++ help files, they explain a fair amount, not always in the best of detail but usually enough to use things