|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
How to Program a Servo
Okay I am not sure how to program the servo, I have a servo plugged into the digital sidecar on PWM #3, and I am not sure how to program it moving so this is the code that we have, so could you tell us our problem?
Code:
#include "WPILib.h"
#include "xmath.h"
class RobotDemo : public SimpleRobot
{
RobotDrive myRobot;
Joystick leftstick;
Joystick rightstick;
Servo servo;
public:
RobotDemo(void):
myRobot(1, 2, 3),
leftstick(1),
rightstick(2),
servo(3)
{
GetWatchdog().SetExpiration(100);
}
void Autonomous(void)
{
GetWatchdog().SetEnabled(false);
//CODE
}
void OperationControl(void)
{
Servo(3);
GetWatchdog().SetEnabled(true);
while(IsOperatorControl())
{
servo.Set(170.0);
GetWatchdog().Feed();
}
}
};
|
|
#2
|
|||
|
|||
|
Re: How to Program a Servo
I think your major problem is that you haven't read any of the documentation on C++ coding: http://first.wpi.edu/Images/CMS/First/FRC1718Docs.zip There's a nice packet of information there. Here's how to fix your program:
Code:
void OperationControl(void)
{
GetWatchdog().SetEnabled(true);
while(IsOperatorControl())
{
servo.Set(1.0);
GetWatchdog().Feed();
}
}
Also, make sure you have a jumper set on the sidecar next to the pwm output for the servo. Last edited by pheadxdll : 02-04-2009 at 09:05 PM. |
|
#3
|
||||
|
||||
|
Re: How to Program a Servo
Quote:
|
|
#4
|
||||
|
||||
|
Re: How to Program a Servo
Quote:
servo.Set() accepts a range from -1 to 1 for min to max values of the servo - this is here so you can just directly accept another float value from something else (like a joystick) and just set it directly. servo.SetAngle() accepts an angle that you wish to set your servo at. Try using this with your 170 angle and see if that works. |
|
#5
|
||||
|
||||
|
Re: How to Program a Servo
Quote:
Quote:
|
|
#6
|
||||
|
||||
|
Re: How to Program a Servo
Oh, right. Most of the other functions are -1 to 1, didn't look at the docs.
If you need to scale (-1, 1) to (0, 1) you can use prevVal = joystick(1)->Get(); //-1 to 1 value ScaledVal = (prevVal + 1)/2; //Scaled to 0 to 1 |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Program a Servo? | programmr | Programming | 5 | 02-10-2008 01:12 PM |
| How to conect solenoids to the circuit board. and how to program it...??? | arpitshah | Pneumatics | 6 | 01-13-2008 03:06 PM |
| Servo Values to Degrees... How? | mogunus | Programming | 16 | 04-11-2007 02:03 AM |
| How much do the servo cost? | Ken Leung | Motors | 2 | 09-14-2001 03:42 PM |