160 likes | 239 Views
2009 Control Systems. Fly By Wire & Autonomous Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Upper Darby Kickoff Jan. 2009. Development Cycle. Joy . A brief moment of optimism usually followed by a crushing downfall! Warning: DO NOT BE FOOLED!. Pain .
E N D
2009 Control Systems Fly By Wire & Autonomous Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Upper Darby Kickoff Jan. 2009
Development Cycle Joy A brief moment of optimism usually followed by a crushing downfall! Warning: DO NOT BE FOOLED! Pain Time – Lots Of It!
Goals • Get you to another room if you think this is a beginner’s seminar. • Get you to understand the Iterative Robot. • Get a good understanding of multi file programming • Get a good understanding of Wind River. • How to edit, debug and load new code via Flash or FTP to the robot. • Learn how to make disabled mode your friend • Learn how to get autonomous working • Presentation and files located at… www.frc272.com/Training/Archive
C vs C++ • A few changes have to be taken into consideration • File extensions end in .cpp and .h • C++ can use classes • Bundle all of a things, things into a single thing. • Example: a joystick has, X, Y & Z variables and many buttons.Joystick->GetX(); • You can get to those “things” if they are public or they can br private. You then use methods to set values, get values. start processes, stop processes etc.compressor->start(); • 3 Requirements to use variables • Create • Servo *my_servo; • Initialize • my_servo = new Servo(5); • Use • my_servo->Set( my_leftStick->GetZ() ); • Bad form for C++ • Servo *my_servo= new Servo(5);
C vs C++ • Pointers vs Local Declarations • Pointers – References to things in memory • Possibly looks cleaner • How most examples are being done. • Declarations – The things in memory • No need for pointers but a little more complicated • Why do I care? • You will see code described both ways. Do not be afraid embrace them. • Declaration Section: class IterativeDemo : public IterativeRobot { // Declare variable for the robot drive system Servo *p_servo; }Note: * means this is a pointer! • Initialization Section: IterativeDemo(void) { printf("IterativeDemo Constructor Started\n"); p_servo = new Servo(5); } • Usage: p_servo->Set(.50); p_servo->Set(p_leftStick->GetZ());
Discoveries • Floating point power ranges • Stated as range is -1.0 to 1.0 with 0.0 being stop. • Declare: Victor p_LeftWinch; // pointer • Initialize: p_LeftWinch = new Victor(2); • Use: p_LeftWinch->Set(0.0); // stop • Forward and Back are relative • 2 motors side set to (1.0) are running at full power. But what direction? • All relative to the motors position. • Turn one around who is forward and who is back. • Joysticks Y axis • Backwards to what you might think? • Push forward get a value of -1.0. • Pull back get 1.0 • Invert (reverse) for use f_WinchPower = -(p_joystick->GetX()); • Opposite motors driving in same direction. One is reversed • f_WinchPower = .50; • p_RightWinch->Set(f_WinchPower); • p_LeftWinch->Set(-f_WinchPower);
Discoveries • Using Wind River • Put all you variables into a structure. Then the intellisense works. typedef struct { Victor *p_FrontLeftMotor; Victor *p_FrontRightMotor; Victor *p_RearLeftMotor; Victor *p_RearRightMotor; Joystick *p_RightDriverStick; Joystick *p_LeftDriverStick; int i_FrontSonar; float f_FrontLeftMotor; float f_FrontRightMotor; float f_RearLeftMotor; float f_RearRightMotor; }struct_robotVars; struct_robotVars my;
Multi File programs • Allow for collaborative effort • Multiple developers taking different roles • Separate files • Start with place holder functions AutonomousPeriodic() { printf(“Auton Periodic: see Jim\n”); } • Developed and tested separately • added to final project • Use .h files to expose variables to others • START_ROBOT_CLASS • Main entry point of program in cRIO. • In Multi file approach move from .h file to main .cpp file. • Prevent multiple instances of this function
What is fly by wire? • No operator direct control of output • Inputs are processed before going to outputs • Something puts in input to variables • CBU (carbon based unit) via Joy Stick my.f_LeftDrive = my.p_LeftStick->GetY(); my.f_RightDrive = my.p_RightStick->GetY(); • SBU (silicon based unit) via autonomous program my.f_LeftDrive = 0.50; my.f_RightDrive = 0.50; • Variables are processed • Changes made depending upon other input my.f_LeftDrive = gyroCorrect(my.f_LeftDrive); my.f_RightDrive = gyroCorrect(my.f_RightDrive); if( sonar < 80) my.f_LeftDrive = my.f_RightDrive = 0.0; • Variables drive the output • Variable set final output motors or switches my.p_LeftMotor = my.f_LeftDrive; my.p_RightMotor = my.f_RightDrive;
IterativeDemo2 Functions • GetDSInputs • Get Driver station inputs and set to variables • Condition inputs for everyone else to use • Reverse sticks • Convert analog to digital • GetRobotSensorInputs • Get inputs from Robot • Sonar, contact switches • RobotThink • Process the inputs • ProcessOutputs • Update the variable to outputs
Basic Idea – Giant Loop • Teleop code is looped through when in teleop mode. TeleopPeriodic() { GetDSInputs(); GetRobotSensorInputs(); RobotThink(); ProcessOutputs(); } • Autonomous code is looped through when in Autonomous mode. AutonomousPeriodic() { GetRobotSensorInputs(); AutoProgramx(); // set vars RobotThink(); ProcessOutputs(); }
DisablePeriodic • Use Disable Mode to test and setup for run • Check sensors (sonar) • Use DS LED to see if sonar is working. • Select Auto Program to Run • Use joystick buttons to set mode • Use trigger to increment program counter. • Use DS LEDs to see what program is selected • #defines set limits • Other possible tests • Is joystick zeroed? • Is gyro working? • Set an autonomous delay
Autonomous Basics • AutoStatus structure • Keeps all Auto vars together • autoStatus.Program • What program should run? • Use switch statements to select program. select(autoStatus.Program) { case 1: autoProgram1(); break; case 2: autoProgram2(); break; case 3: autoProgram3(); break; } Note: autoPrograms can be in separate files.
Autonomous State Machine • autoStatus.step • What am I doing now • Parts of a step • Initialize • Set up the step to be performed • Set flag indicating setup done. • Perform Step • Change variables to make something happen • Test to see if step is complete • Did I go far enough? • Is a wall is in front of me? • Is the timer up? • Cleanup • Unset setup done flag • Bump step
Final Thought Unlike baseball crying is allowed in software development… but … …when your done, get back and make it work!