![Page 1: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/1.jpg)
2010 Control Systems
All we are saying…
…is give C a chance!
Presented By:
Frank Larkin
Lansdale Catholic Robotics, Team 272
Radnor PA, Dec. 2010
![Page 2: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/2.jpg)
Development Cycle
Joy
Pain
Time – Lots Of It!
A brief moment of optimism usually
followed by a crushing downfall!
Warning: DO NOT BE FOOLED!
![Page 3: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/3.jpg)
Big Al says…
![Page 4: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/4.jpg)
Goals• Get you to the other room if you
want to learn Labview. • Get a good understanding of what
the new control system can and cannot do.
• Get a good understanding of how to program in C++– Be able to create your own classes to
allow multiple threads for development.
• 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 get autonomous working
![Page 5: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/5.jpg)
How will we do it?• Discuss C++
– No rat holing on C++ theory. – Too much for this venue– Exchange cards, get phone numbers
and email• Review online resources
– Forums, Wiki, bla bla• Review beta code to explore
possibilities– Get many flavors of the same thing. – Touches many of the approaches
available to you– See how other accomplished– Shamelessly steal their stuff.
• Hands On– Play utill it is time to leave.
![Page 6: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/6.jpg)
Control System Overview
CompactRIO
WiFiBridge
SpeedController
SpeedController
SpikeRelay
DigitalSensor
AnalogSensor
DigitalSide Car
AnalogBumper
Solenoid
PneumaticsBumper
![Page 7: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/7.jpg)
Software OverviewThe WPI Robotics Libraries
• Sensors– Accelerometer, Encoder, Gear Tooth, Gyro,
Compass, I2C, Ultrasonic
• Actuators– Compressor, Motor (Victor, Jaguar), Relay, Servo,
Solenoid
• I/O– Analog Channel, Analog Trigger, Digital Input,
Digital Output, PWM
• Driver Station– Joystick (Complete set of Axes and Buttons),
Analog Input, Digital Input, Digital Output, Driver Display, Mode, Alliance, Battery Voltage, Dashboard
• Utility– Counter, PID, Drive (Tank, Arcade, Holonomic),
Time, cRIO LED, cRIO Temperature
• Vision– Camera, Tracking, Image Processing
![Page 8: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/8.jpg)
Modes Of Operation• Disabled Mode: Before a match
begins, robot outputs (motors) are not active. Robots can be programmed to initialize. Driver controls are active.
• Autonomous Mode: During the first 15 seconds of a match, driver inputs (joysticks) are not active. Robots can be programmed to use outputs (motors) and sensor inputs (encoders, gyros) for autonomous operation.
• Teleoperated Mode: During the remaining 120 seconds of a match, all inputs and outputs are active. Robots are programmed for driver control.
![Page 9: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/9.jpg)
Program PhilosophyThe Big Loop
ReadDriverStation()
Process DataRobotThink()
WriteOutputs()
ReadSensors()
If (autonomous)doAuto()
![Page 10: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/10.jpg)
C++• Software Development Cycle
– Create Source Code• Type ideas into files• Multiple authors of different components
– Compile and Link program• Compile – Read source code for each file,
create object .obj for it. • Linker - combine each object into and
executable file.
– Download Executable to RAM– Run and Debug
• LabVIEW Input/Output Available on vi Front Panel
• C++ WindRiver Debugger• C++ Output Available in Console
– Download Debugged Executable to Flash
– Reboot cRIO• Power Cycle or CTRL-X in Terminal
– Run
![Page 11: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/11.jpg)
Quick Tour of C++• 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 be private. You then use methods to set values, get values. start processes, stop processes etc.compressor->start();
• C++ uses static constants and functions which must be referred back to the original class they were part of.
• In C++: LCRobots::MacLeftMotor
• 3 Requirements to use variables– Define Servo *my_servo;
– Initialize my_servo = new Servo(5);
– Use my_servo->Set( my_leftStick->GetZ() );
![Page 12: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/12.jpg)
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 systemServo *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());
![Page 13: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/13.jpg)
Declared Example• Declaration Section:class IterativeDemo : public IterativeRobot{
// Declare variable for the robot drive systemServo m_servo;Joystick m_leftStick;Joystick m_RightStick;Joystick m_OperatorStick;
}
• Initialization Section:IterativeDemo(void) : m_servo(5), m_leftStick(), m_rightStick(),
m_operatorStick(){}
• Usage:m_servo.Set( leftStick.GetZ() );
• How do I keep it all straight?– Liberal use of variable prefixes can help.
• p_servo, p_leftJoystick; = pointers• i_count = integer (not a pointer)• ip_speed = integer pointer (may never see this).• f_motorPower = floating point variable• m_stuff = member variable (used in many beta
examples)– This should scare you…..
• p_servo.Set(5);
![Page 14: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/14.jpg)
Death By Pointer
• Which is correct?IterativeDemo(void){
printf("IterativeDemo Constructor Started\n");
my.p_servo->set(0.0);
my.p_servo = new Servo(5);
};
• What happens if you do it wrong?– It will compile– The DS will show Ok– It will not run.– “Slow Blinking LED of Doom!”
![Page 15: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/15.jpg)
Death By Pointer• Startup of program on cRIO
Exception current instruction address: 0x012eb5c8Machine Status Register: 0x0000b032Data Access Register: 0x537fb81bCondition Register: 0x20000048Data storage interrupt Register: 0x40000000Task: 0x1307e98 "FRCRobotTask"0x1307e98 (FRCRobotTask): task 0x1307e98 has had a
failure and has been stopped.
0x1307e98 (FRCRobotTask): fatal kernel task-level exception!
Welcome to LabVIEW Real-Time 8.5.1Indicator Mode changed... Slow Blink
• Driver Station shows correctly
• Do not panic over the slow blink of death!– May be a pointer issue. Do a code review
looking for illegal use of pointers.p_servo.Set(0.0); // p_ indicates pointer!!!p_servo->Set(0.0); // correct
![Page 16: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/16.jpg)
Good Boot Up
• Startup of program on cRIO
Resync command from DS...Resync command from DS...Enabled!Booting watchdog!Indicator Mode changed... Steady OnWPILib was compiled from SVN revision 1330:1345Spawned FRCRobotTask (0x12f7b70)RobotIterativeBase Constructor StartRobotIterativeBase Constructor FinishIterativeDemo Constructor StartedIterativeDemo Constructor CompletedRobotIterativeBase StartCompetition() CommencedTeleop_Init() completed
Welcome to LabVIEW Real-Time 8.5.1
![Page 17: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/17.jpg)
Discoveries• Floating point power ranges
– Stated as range is -1.0 to 1.0 with 0.0 being stop.
• Declare: Victor p_LeftMotor; // pointer• Initialize: p_LeftMotor=> new Victor(2);• Use: p_LeftMotor->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
– Easy to reverse motor in code.• f_WinchPower = .50;• p_RightWinch->Set(f_WinchPower);• p_LeftWinch->Set(-f_WinchPower);
![Page 18: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/18.jpg)
Discoveries• Simple math is your
friend!• Joystick “twist” comes in
a GetZ()– Range 1.0 to -1.0– What does this do?
my.f_Power = ((-my.p_LeftDriverStick->GetZ() / 2) + 0.5);
• Turns analog range of 1.0/ -1.0 to 0.0/1.0
• Use excel to help figure out value ranges
![Page 19: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/19.jpg)
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;
![Page 20: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/20.jpg)
Batch Files• Use batch files to quickly
change computer ethernet connection. – You must know what your
connection is called.
![Page 21: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/21.jpg)
netsh Command• netsh – used to set network
parametersCommand: netsh /? To see
parameters
• Example: Set interface to Crio
Note: In the example above the netsh command is on the same line!
@echo offecho Setting the Ip to CRIO network 10.2.72.6.
netsh interface ip set address name="Local Area Connection" static 10.2.72.6 255.0.0.0
pause
![Page 22: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/22.jpg)
Many batches• Set to camera
• Set to DHCP
Note: All the above commands are set on the same batch line.
netsh interface ip set address name="Local Area Connection" dhcp
netsh interface ip set address name="Local Area Connection" static 10.2.72.3 255.0.0.0
![Page 23: 2010 Control Systems All we are saying… …is give C a chance! Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 Radnor PA, Dec. 2010](https://reader036.vdocuments.us/reader036/viewer/2022081519/56649e4c5503460f94b40c42/html5/thumbnails/23.jpg)
Final ThoughtUnlike baseball crying is allowed in
software development… but …
…when your done, get back and make it work!