View Single Post
  #3   Spotlight this post!  
Unread 25-01-2014, 00:38
kylelanman's Avatar
kylelanman kylelanman is offline
Programming Mentor
AKA: Kyle
FRC #2481 (Roboteers)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2007
Location: Tremont Il
Posts: 190
kylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to all
Re: How to Program a Servo

If you can use robot builder to create your subsystem and commands. Robot builder is create for beginners. Always make sure to review the code it generates and try to understand what it is doing.

The basic approach (no code. I'm a C++ guru and am not confident I would not provide broken java code.).

Create a subsystem and add a Servo to it or add a Servo object to an appropriate existing subsystem.

Solution A

Create a command that moves the servo to position 1.
Create a command that moves the servo to position 2.
Create a command group that adds sequentially:
--MoveServoToPos1Command
--WaitCommand(timeItTakesForServoToRotate45Deg)
--MoveServoToPos2Command
Assign command group to a joystick button.

Solution B
Create a command that moves the servo to position 1 and then waits the timeItTakesForServoToRotate45Deg and then moves the servo to position 2.

The choice is up to you how much you want to break the problem down. 1 command will work but a command group of discrete commands would be more flexible.
__________________
"May the coms be with you"

Is this a "programming error" or a "programmer error"?