Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   How to Program a Servo (http://www.chiefdelphi.com/forums/showthread.php?t=73625)

ExarKun666 04-02-2009 20:49

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();
  }
}
};

So any suggestions?

pheadxdll 04-02-2009 21:02

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();
  }
}

The Set method takes a value from 0.0 to 1.0 (full left to full right)

Also, make sure you have a jumper set on the sidecar next to the pwm output for the servo.

byteit101 05-02-2009 14:47

Re: How to Program a Servo
 
Quote:

The Set method takes a value from 0.0 to 1.0 (full left to full right)
Not on a servo (last i checked it is 0-170) though I don't know about the team update 3

3DWolf 06-02-2009 13:40

Re: How to Program a Servo
 
Quote:

Originally Posted by byteit101 (Post 814770)
Not on a servo (last i checked it is 0-170) though I don't know about the team update 3

You're getting your functions confused.
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.

byteit101 06-02-2009 16:45

Re: How to Program a Servo
 
Quote:

Originally Posted by 3DWolf (Post 815366)
You're getting your functions confused.
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.

it is 0 to 1 not -1 to 1
Quote:

Originally Posted by WPILib
/**
* Set the servo position.
*
* Servo values range from 0.0 to 1.0 corresponding to the range of full left to full right.
*
* @param value Position from 0.0 to 1.0.
*/
void Servo::Set(float value)


3DWolf 06-02-2009 21:05

Re: How to Program a Servo
 
Quote:

Originally Posted by byteit101 (Post 815497)
it is 0 to 1 not -1 to 1

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


All times are GMT -5. The time now is 02:57.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi