|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#5
|
||||
|
||||
|
Re: Autonomous mode help
try this
RobotDemo() { GetWatchdog().SetEnabled(false); } Example 4: Disabling the watchdog timer Now the autonomous part of the program can be constructed that drives in a square pattern: void Autonomous() { for (int i = 0; i < 4; i++) { drivetrain.Drive(0.5, 0.0); // drive 50% of full forward with 0% turn Wait(2.0); // wait 2 seconds drivetrain.Drive(0.0, 0.75); // drive 0% forward and 75% turn } Drivetrain.Drive(0.0, 0.0); // drive 0% forward, 0% turn (stop) } Example 5: Autonomous program that drives in a square pattern Now look at the operator control part of the program: void OperatorControl() { while (1) // loop forever { drivetrain.TankDrive(leftStick, rightStick);// drive with the joysticks Wait(0.005); } } Example 6: Simple tank drive with two joysticks Putting it all together we get this very short program that accomplishes some autonomous task and provides operator control tank steering: #include “WPILib.h” class RobotDemo : public SimpleRobot { RobotDrive drivetrain(1, 2); Joystick leftStick(1); Joystick rightStick(2); public: RobotDemo() { GetWatchdog().SetEnabled(false); } void Autonomous() { for (int i = 0; i < 4; i++) { drivetrain.Drive(0.5, 0.0); // drive 50% forward, 0% turn Wait(2.0); // wait 2 seconds drivetrain.Drive(0.0, 0.75); // drive 0% forward and 75% turn Wait(0.75); // turn for almost a second } drivetrain.Drive(0.0, 0.0); // stop the robot } void OperatorControl() { while (1) // loop forever { drivetrain.Tank(leftStick, rightStick); // drive with the joystick Wait(0.005); } } }; Example 7: Completed example program Although this program will work perfectly with the robot as described, there were some details that were skipped: In the example drivetrain,leftStick and rightStick are member objects of the RobotDemo class. They were accessed using references, one of the ways of accessing object members. In the next section pointers will be introduced as an alternate technique. The drivetrain.Drive() method takes two parameters, a speed and a turn direction. See the documentation about the RobotDrive object for details on how that speed and direction really work. The Watchdog timer was disabled – in general a bad idea! You should enable the watchdog timer, set the feeding interval, and be sure to “Feed” it at least that often. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| autonomous mode help please... | tomy | NI LabVIEW | 22 | 21-02-2009 10:04 |
| Autonomous mode help | Drake Hunter | NI LabVIEW | 3 | 12-02-2009 01:52 |
| Autonomous Mode HELP! | jesusescobar | Programming | 4 | 12-02-2007 12:02 |
| Help - Making the autonomous mode | razer | Programming | 5 | 31-01-2007 16:25 |
| Simulating autonomous mode - i need help!! :( | itay_ms | Programming | 5 | 21-01-2007 11:28 |