|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
? 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? |
|
#2
|
||||
|
||||
|
Re: ? programming servos
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 Code:
GetWatchdog().SetEnabled(false); )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. ![]() |
|
#3
|
||||
|
||||
|
Re: ? programming servos
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).
Code:
#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
#define SERVO_CHANNEL 1
class RobotDemo : public SimpleRobot
{
Servo servo;
Joystick stick;
public:
RobotDemo(void):
servo(DIGITAL_SLOT_1, SERVO_CHANNEL),
stick(1)
{
GetWatchdog().SetExpiration(0.1);
}
void OperatorControl(void)
{
GetWatchdog().SetEnabled(true);
while (IsOperatorControl())
{
GetWatchdog().Feed();
// control the servo with a joystick
servo.Set( stick.GetDirectionDegrees() );
Wait(0.005); // wait for a motor update time
}
}
};
START_ROBOT_CLASS(RobotDemo);
|
|
#4
|
|||
|
|||
|
Re: ? programming servos
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.
|
|
#5
|
|||
|
|||
|
Re: ? programming servos
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. |
|
#6
|
|||
|
|||
|
Re: ? programming servos
to declare one is fairly easy,
try: AnalogChannel *pot; pot=new AnalogChannel(<channel>); then to get the voltage from it: pot->GetVoltage(); check out the c++ help files, they explain a fair amount, not always in the best of detail but usually enough to use things |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Programming Servos. | chsrobotics3283 | NI LabVIEW | 9 | 31-01-2010 20:47 |
| Programming Servos on ROBOTC? | megaman295 | Programming | 1 | 27-01-2010 16:43 |
| Servos in C | superspork22 | C/C++ | 2 | 19-01-2009 21:42 |
| Shuper Shifter servos hookup and programming | MiniNerd24 | General Forum | 4 | 30-01-2008 21:59 |
| Programming Servos For AndyMark Transmission | de_ | Programming | 6 | 30-01-2007 08:52 |