Tele Operations (Remote Control) with RobotC and Mindstorms.

This lesson provides a basic program to control a Tetrix/Mindstorm Robot with a Logitech USB Remote Control.  This provides the foundation for human controlled robot operations such as are used for the First Tech Competition.  

RobotC provides some good basic templates for remote Control.  You will find these templates under "File -> New -> User Control Template."  You can also open Sample Programs.  

For this Lesson - we will create a User Control program from scratch to cover each step of creating the code.  The remote is shown below with the controls labeled for this particular program:

This lesson is based on the ICEBot with a servo on Channel 1 controlling the Arm and the NXT Motor in Port C controlling the hand.  The Hi-Tech Hubs are connected to Sensor Port 1 on the Brick.


Step 1:  Declare Motors and Sensors
(See Introduction to RobotC and Tetrix for detailed instructions on Setting Up Motors and Sensors)

1. Select File -> New from RobotC.
2. Save your program as "TeleOpTest.c"
3. Select "Robot -> Motors and Sensors Setup"
4. Select the Tetrix Controllers Tab.  Select the "Standard Configuration" button.
5. Click Apply.
6. Click the Motors Tab.  Type "Hand" for motorC.  Select "Reversed" for motorE.
7. Click "Apply."
8. Click the "Servos" Tab.  Type "Arm" in the place for servo1.  Click "Apply."
9. Click "OK."

Step 2.  The "include" file and variables.

1.  Note that the first 11 lines (perhaps less) have the #pragma codes that declare the motors and servos.  

2. Start on Line 13.  Type Lines 13 to 21 as shown below.  

Line 11 imports the codes to get values from the joystick.
Lines 17-19 declare variables we will use later.  
-ArmPosition:  Up and Down position of the servo Arm
-DPower: Power for D motor
-EPower: Power for E Motor

Step 3:  initializeRobot() method

1. Type lines 23 to 29.  This method sets the robot's starting position when the program starts.  (Lifting Arm to top position).

Step 4:  Methods to Operate Hand

1. Type lines 31 to 46.  These two methods will Open and Close the hand.

Step 5:  Methods to Operate Arm

1. Type Lines 48 to 66.  These methods raise and lower the Arm in small increments when the user holds down certain buttons on the controller.  (To be defined later in the task main())

Step 6:  Start of Main Method

1.  Type lines 68 to 95.  

First, we put the robot in starting position with "initializeRobot()."  Then, the "waitForStart()"  poises the robot for a signal from the computer to begin reading data from the controller.  The "while(true)" segment is an infinite loop that takes data from the controller and calls methods to move the Hand, Arm, and motors.  The "getJoystickSettings(joystick);" makes the Joystick values available to the program.  

Lines 80 to 95 bring in the values y  from the "Thumb Buttons"  "joystick.joy1_y1" is the Left Thumb.  "joystick.joy1_y2" is the right Thumb.  We divide by 8 to keep the values small (The range on the Joystick is from -255 to 255).  The if statements use the absolute power function to set the motors to zero if the controllers are towards the rest position.  This keeps the robot from "jittering."

Step 7:  Arm and Hand Controls

1.  Type Lines 96 to 117.  These use the Right Thumb buttons (1, 2, 3, 4) to call methods to move the hand and arms.

2.  Save your program.

Step 8.  Running the program.

1. This step can cause confusion.  The program does not directly launch like an autonomous program.  Press "F5" to download and run program.  Then click "Start."

2. The program now is waiting for the "Start" from the computer.  Select "Robot->NXT Brick->Joystick Control - Game"

3.  A window with the image of the Joystick appears.  Make sure your TeleOp program is selected from the drop down menu.  Then click "Tele Op:Ready" button.  Then click "Tele Op: Running" to start the remote control.

Email Mr.Michaud

Copyright ©2011 Mr. Michaud.