View Single Post
  #3   Spotlight this post!  
Unread 16-02-2010, 08:51
virtuald's Avatar
virtuald virtuald is online now
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,055
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