LC272 - Give_C_A_Chance (2010 season)

advertisement
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
Development Cycle
Joy

A brief moment of
optimism usually
followed by a crushing
downfall!
Warning: DO NOT BE
FOOLED!
Pain

Time – Lots Of It!
Big Al says…
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
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.
Control System Overview
WiFi
Bridge
CompactRIO
Digital
Sensor
Speed
Controller
Speed
Controller
Pneumatics
Bumper
Digital
Side Car
Solenoid
Analog
Bumper
Spike
Relay
Analog
Sensor
Software Overview
The 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
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.
Program Philosophy
The Big Loop
ReadDriverStation()
ReadSensors()
If (autonomous)
doAuto()
Process Data
RobotThink()
WriteOutputs()
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
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
– Initialize
– Use
Servo *my_servo;
my_servo = new Servo(5);
my_servo->Set( my_leftStick->GetZ() );
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());
Declared Example
• Declaration Section:
class IterativeDemo : public IterativeRobot
{
// Declare variable for the robot drive system
Servo 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);
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!”
Death By Pointer
• Startup of program on cRIO
Exception current instruction address: 0x012eb5c8
Machine Status Register: 0x0000b032
Data Access Register: 0x537fb81b
Condition Register: 0x20000048
Data storage interrupt Register: 0x40000000
Task: 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.1
Indicator 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
Good Boot Up
• Startup of program on cRIO
Resync command from DS...
Resync command from DS...
Enabled!
Booting watchdog!
Indicator Mode changed... Steady On
WPILib was compiled from SVN revision 1330:1345
Spawned FRCRobotTask (0x12f7b70)
RobotIterativeBase Constructor Start
RobotIterativeBase Constructor Finish
IterativeDemo Constructor Started
IterativeDemo Constructor Completed
RobotIterativeBase StartCompetition() Commenced
Teleop_Init() completed
Welcome to LabVIEW Real-Time 8.5.1
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);
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
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;
Batch Files
• Use batch files to quickly
change computer ethernet
connection.
– You must know what your
connection is called.
netsh Command
• netsh – used to set network
parameters
Command: netsh /? To see
parameters
• Example: Set interface to Crio
@echo off
echo 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
Note: In the example above the netsh
command is on the same line!
Many batches
• Set to camera
netsh interface ip set address name="Local Area Connection"
static 10.2.72.3 255.0.0.0
• Set to DHCP
netsh interface ip set address name="Local Area Connection"
dhcp
Note: All the above commands
are set on the same batch line.
Final Thought
Unlike baseball crying is allowed in
software development… but …
…when your done, get back and
make it work!
Download