intermediate robotc - first in maryland · intermediate robotc teleop coding teams 5233 vector and...

20
Intermediate RobotC Teleop Coding Teams 5233 Vector and 5293 Rexbotics [email protected]

Upload: duongkiet

Post on 05-Jun-2018

229 views

Category:

Documents


0 download

TRANSCRIPT

Intermediate RobotC

Teleop Coding

Teams 5233 Vector and

5293 Rexbotics

[email protected]

Getting Started

• Select platform

• New User Control Template

• Configure Robot (robot -> Motor and Sensors Setup)

Writing Code

• Plan

• Code

– In small pieces, tested at each step

• Refine

– Debugging: finding and fixing errors

– Refactoring: improving the performance of working code

– Extending: adding features to working code

The Teleop Template

• Handles communication between NXT, Samantha, and field control

• Provides the ability to read joysticks

• Your only job: read the joysticks and respond to them!

Planning the Teleop

struct TJoystick

/* from JoystickDriver.c */{bool UserMode; // Autonomous or Telep-Operated modebool StopPgm; // Stop program

short joy1_x1; // -128 to +127short joy1_y1; // -128 to +127short joy1_x2; // -128 to +127short joy1_y2; // -128 to +127short joy1_Buttons; // Bit map for 12-buttonsshort joy1_TopHat; // value -1 = not pressed, otherwise 0 to 7 for selected "octant".

short joy2_x1; // -128 to +127short joy2_y1; // -128 to +127short joy2_x2; // -128 to +127short joy2_y2; // -128 to +127short joy2_Buttons; // Bit map for 12-buttonsshort joy2_TopHat; // value -1 = not pressed, otherwise 0 to 7 for selected "octant".

} TJoystick;

Drive Styles: Tank

• right joystick controls right wheel, left joystick controls left wheel.

task main(){

while (true){

getJoystickSettings(joystick);motor[LeftWheel] = joystick.joy1_y1;motor[RightWheel] = joystick.joy1_y2;wait1Msec(5);

}}

+

Drive Styles: Arcade

• Y-axis moves bot forward/back, X-axis turns bot.

task main(){

while (true){

getJoystickSettings(joystick);motor[LeftWheel]= joystick.joy1_y1 + joystick.joy1_x1/2;motor[RightWheel]= joystick.joy1_y1 - joystick.joy1_x1/2;wait1Msec(5);

}}

+

Teleop 1.0

task main(){initializeRobot();

waitForStart(); // wait for start of tele-op phase

while (true){

getJoystickSettings(joystick);

motor[LeftWheel] = joystick.joy1_y1;motor[RightWheel] = joystick.joy1_y2;

wait1Msec(5);

}}

Reading Buttons

if (joy1Btn(6)) {motor[BallCatcher] = 75;

}else if (joy1Btn(5)) {

motor[BallCatcher] = -75;}else {

motor[BallCatcher] = 0;}

Setting the NXT for Teleop Use

Refactoring

• Archive!

• Plan

• Code

• Test again

Teleop 1.1

task main(){

initializeRobot();waitForStart(); // wait for start of tele-op phasewhile (true){

getJoystickSettings(joystick);motor[LeftWheel] = joystick.joy1_y1;motor[RightWheel] = joystick.joy1_y2;

if (joy1Btn(6)) {motor[BallCatcher] = 75;

}else if (joy1Btn(5)) {

motor[BallCatcher] = -75;}else {

motor[BallCatcher] = 0;}wait1Msec(5);

}}

Code Management

• Archive successful revisions

• Force backup at end of each session

• Before each competition (24 hr or more!)

– Wipe NXT

– Reinstall with clean software

– Test each program

Teleop 2.0

// Two-driver versiontask main(){

initializeRobot();waitForStart(); // wait for start of tele-op phasewhile (true){

getJoystickSettings(joystick);motor[LeftWheel] = joystick.joy1_y1;motor[RightWheel] = joystick.joy1_y2;

if (joy2Btn(6)) {motor[BallCatcher] = 75;

}else if (joy2Btn(5)) {

motor[BallCatcher] = -75;}else {

motor[BallCatcher] = 0;}wait1Msec(5);

}}