Go to Post FRC did a lot for me in high school. I couldn't pass up the opportunity to help it do the same for others. - Oblarg [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 15-02-2010, 21:05
whatabouteve whatabouteve is offline
Registered User
AKA: Dean Keithly
FRC #0245 (Adambots)
Team Role: Leadership
 
Join Date: Jan 2009
Rookie Year: 2007
Location: Rochester Hills,MI
Posts: 45
whatabouteve is an unknown quantity at this point
? 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?
Reply With Quote
  #2   Spotlight this post!  
Unread 16-02-2010, 00:24
buddyb's Avatar
buddyb buddyb is offline
Registered User
FRC #1885 (ILITE)
Team Role: Programmer
 
Join Date: Dec 2009
Rookie Year: 2008
Location: Haymarket, VA
Posts: 65
buddyb has a spectacular aura aboutbuddyb has a spectacular aura aboutbuddyb has a spectacular aura about
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);
in your teleoperated code. (If the Watchdog is not fed, it keeps most things from running on your robot. )

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.
__________________
FRC - Team 1885 - Programmer.
Reply With Quote
  #3   Spotlight this post!  
Unread 16-02-2010, 08:51
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,082
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
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);
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #4   Spotlight this post!  
Unread 16-02-2010, 09:38
Mike Mahar Mike Mahar is offline
Registered User
FRC #0138
 
Join Date: Jan 2007
Location: Amherst, NH
Posts: 64
Mike Mahar will become famous soon enough
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.
Reply With Quote
  #5   Spotlight this post!  
Unread 16-02-2010, 20:09
whatabouteve whatabouteve is offline
Registered User
AKA: Dean Keithly
FRC #0245 (Adambots)
Team Role: Leadership
 
Join Date: Jan 2009
Rookie Year: 2007
Location: Rochester Hills,MI
Posts: 45
whatabouteve is an unknown quantity at this point
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.
Reply With Quote
  #6   Spotlight this post!  
Unread 18-02-2010, 08:58
Zme Zme is offline
Registered User
FRC #2619
 
Join Date: Jan 2009
Location: Michigan
Posts: 83
Zme is on a distinguished road
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
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
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


All times are GMT -5. The time now is 03:25.

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