View Single Post
  #14   Spotlight this post!  
Unread 20-03-2012, 20:09
rbmj rbmj is offline
Registered User
FRC #0612 (Chantilly Robotics)
Team Role: Alumni
 
Join Date: Apr 2011
Rookie Year: 2011
Location: DC Area/Fairfax County
Posts: 192
rbmj is a jewel in the roughrbmj is a jewel in the roughrbmj is a jewel in the rough
Re: Newbie Alert. Our robot is competing, and I can't program it.

Ok. Let me go through this.

Here's a sample program using SimpleRobot. Most of this is in the GettingStartedWithC pdf, but...

Code:
#include <WPILib.h>

class my_robot : public SimpleRobot {
private:
    //the names are completely arbitrary.
    Jaguar left_front_drive;
    Jaguar left_rear_drive;
    Jaguar right_front_drive;
    Jaguar right_rear_drive;
    Jaguar actuator_yournamehere;
    Jaguar actuator_someothername;
    RobotDrive drive;
    Joystick drive_joystick;
public:
    my_robot();
    void RobotInit();
    void Disabled();
    void Autonomous();
    void OperatorControl();
};

my_robot::my_robot() : //call constructors for all members of my_robot
    //PWM Ports
    left_front_drive(1), //replace with your actual ports
    left_rear_drive(2), //ask your electrical team for the port numbers
    right_front_drive(3),
    right_rear_drive(4),
    actuator_yournamehere(5),
    actuator_someothername(6),
    //RobotDrive object
    drive(
        left_front_drive,
        left_rear_drive,
        right_front_drive,
        right_rear_drive
    ),
    drive_joystick(1) //joystick 1
{
    //constructor.  Initializes all objects (above)
}

void my_robot::RobotInit() {
    //any run-time initialization you need goes here
}

//The following functions will be called exactly once
//after they have run the robot will just sleep until
//a state change (e.g. Autonomous to Disabled)
void my_robot::Disabled() {
    //disabled code.
}

void my_robot::Autonomous() {
    //your autonomous code should go here.
    //make dead sure that this function returns
    //before the start of TeleOp or your robot will
    //be a brick
}

void my_robot::OperatorControl() {
    while (IsOperatorControl()) {
        drive.ArcadeDrive(drive_joystick);
        if (drive_joystick.GetRawButton(1)) { //use whatever button you need
            actuator_yournamehere.Set(1.0); //use whatever power you want
        }
        else {
            actuator_yournamehere.Set(0.0); //turn off
        }
        if (drive_joystick.GetRawButton(2)) {
            actuator_someothername.Set(-1.0); //say reverse, whatever
        }
        else {
            actuator_someothername.Set(0.0);
        }
    }
}

START_ROBOT_CLASS(my_robot);
This is very minimal code, but I hope it's enough to get you started.

I'm coding from memory and don't have anything to test it on, so there may be some errors.

I hope that between this and the documentation you can figure out how to adapt this for your circumstances.

If you need more help, you know where to ask.
Reply With Quote