Go to Post You should take in to consideration who you are putting on to the field, not what. - NorviewsVeteran [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 04-02-2009, 20:49
ExarKun666's Avatar
ExarKun666 ExarKun666 is offline
Ben Error/MC Ben/NC Ben
AKA: Ben Kellogg
FRC #2429 (LCEC)
Team Role: Programmer
 
Join Date: Dec 2007
Rookie Year: 2008
Location: La Caņada, CA
Posts: 208
ExarKun666 is an unknown quantity at this point
Send a message via AIM to ExarKun666 Send a message via MSN to ExarKun666 Send a message via Yahoo to ExarKun666
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?
__________________
Ben Kellogg




Team Sites: [LCEC Site] [FRC/FLL Site] [LCEC Blog]
Reply With Quote
  #2   Spotlight this post!  
Unread 04-02-2009, 21:02
pheadxdll pheadxdll is offline
Registered User
AKA: Alex
FRC #1225 (Amperage Robotics)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2006
Location: North Carolina
Posts: 168
pheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud ofpheadxdll has much to be proud of
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.
__________________
Amperage Robotics Team 1225
Site under-going revamp. :/

Last edited by pheadxdll : 04-02-2009 at 21:05.
Reply With Quote
  #3   Spotlight this post!  
Unread 05-02-2009, 14:47
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
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
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
Reply With Quote
  #4   Spotlight this post!  
Unread 06-02-2009, 13:40
3DWolf's Avatar
3DWolf 3DWolf is offline
Boots - Head Programmer / 3D
AKA: Jake
FRC #1502 (Technical Difficulties)
Team Role: Programmer
 
Join Date: Dec 2006
Rookie Year: 2005
Location: Chelsea Michigan
Posts: 97
3DWolf is on a distinguished road
Send a message via AIM to 3DWolf Send a message via MSN to 3DWolf
Re: How to Program a Servo

Quote:
Originally Posted by byteit101 View Post
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.
__________________
You can call it the programming teams fault, but we'll just force your arguments nil.

There are 10 kinds of people in the world -> Those who understand binary and those who don't.

WYSIWYG - In FIRST: Greatness
Reply With Quote
  #5   Spotlight this post!  
Unread 06-02-2009, 16:45
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: How to Program a Servo

Quote:
Originally Posted by 3DWolf View Post
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)
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
Reply With Quote
  #6   Spotlight this post!  
Unread 06-02-2009, 21:05
3DWolf's Avatar
3DWolf 3DWolf is offline
Boots - Head Programmer / 3D
AKA: Jake
FRC #1502 (Technical Difficulties)
Team Role: Programmer
 
Join Date: Dec 2006
Rookie Year: 2005
Location: Chelsea Michigan
Posts: 97
3DWolf is on a distinguished road
Send a message via AIM to 3DWolf Send a message via MSN to 3DWolf
Re: How to Program a Servo

Quote:
Originally Posted by byteit101 View Post
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
__________________
You can call it the programming teams fault, but we'll just force your arguments nil.

There are 10 kinds of people in the world -> Those who understand binary and those who don't.

WYSIWYG - In FIRST: Greatness
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Program a Servo? programmr Programming 5 10-02-2008 13:12
How to conect solenoids to the circuit board. and how to program it...??? arpitshah Pneumatics 6 13-01-2008 15:06
Servo Values to Degrees... How? mogunus Programming 16 11-04-2007 02:03
How much do the servo cost? Ken Leung Motors 2 14-09-2001 15:42


All times are GMT -5. The time now is 14:53.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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