When the autonomous period ends, how do we call out the teleops program we would like to run? I've watched the webinars, and they tell me I need to call out the teleops program at the end of my autonomous code, but how do we do that? Is it as simple as just putting the name of the file at the end of the program, or is there a function we are overlooking?

_________________Trying to help you will be like trying to find a worm in the middle of a blizzard. A white worm.

Fri Dec 05, 2008 6:17 pm

VikeBots

Rookie

Joined: Sat Dec 06, 2008 1:47 pmPosts: 1

Re: how do we switch to teleops program?

Change the "Teleop Program Name" in your debug window. A text file is created on the NXT, and the FMS will switch automatically for you at the competition.

Sat Dec 06, 2008 1:50 pm

dgbatths

Rookie

Joined: Mon Nov 03, 2008 1:45 pmPosts: 14

Re: how do we switch to teleops program?

Why can't both autonomous and tele-op code be in the same program? The joystick struct has a flag indicating whether the FMS is in autonomous mode or not.

_________________David BurnetteTigard High School Robotics

Tue Dec 09, 2008 7:59 pm

tfriez

Site Admin

Joined: Wed Jan 24, 2007 10:42 amPosts: 618

Re: how do we switch to teleops program?

It's the way the field management system works. Even if you choose the same program for "tele-op" as you start for autonomous, during the "pause" period between modes, the FMS will restart your program.

We created this single program template which follows all of the rules:

Code:

#include "JoystickDriver.c"

void autonomous(){ // autonomous code goes here}

void drive(){ // user drive code goes here}

task UserCode(){ if (joystick.UserMode) drive(); else autonomous();}

task main(){ getJoystickSettings(joystick);

// wait for the FMS to start autonomous or driver control mode while (joystick.StopPgm) { wait10Msec(2); getJoystickSettings(joystick); }

StartTask(UserCode);

// Keep polling the joysticks and keep an eye on the stop flag. while (!joystick.StopPgm) { wait10Msec(2); getJoystickSettings(joystick); }

StopTask(UserCode); stopMotors();}

_________________Jeff McBrideBenson Robotics Club

Thu Dec 11, 2008 12:17 pm

BillW

Rookie

Joined: Fri Dec 12, 2008 1:59 amPosts: 2

Re: how do we switch to teleops program?

Jeff,

Your code appears to be a good approach to having a single program. Have you verified that it works with an FMS?

Also, have you experienced any problems when using tasks? Not that I am aware of any--we just haven't used yet.

Thanks.

--Bill Wiley

Fri Dec 12, 2008 2:12 am

Jeff McBride

Professor

Joined: Fri Sep 19, 2008 1:22 amPosts: 200

Re: how do we switch to teleops program?

We were one of the teams that were chosen last spring to participate in the beta program and showcase tournament for the Tetrix platform. We have found tasks to be very useful and quite manageable. There are a couple of things that you should keep in mind when using tasks.

1) You can not call the same subroutine from more than one task. This is because all local variables are actually static globals rather than being on the stack.

2) If you have a function that you need to call from multiple tasks you can use the "inline" keyword in the function declaration. That will make the compiler insert the body of the function inline in the caller.

3) You should avoid trying to adjust the priorities of the tasks. Instead, each task should yield the CPU with a wait statement inside any loops. Notice the wait in the main task of my template for an example. Multiple tasks will still function if you do not use wait statements but it is always a good idea but a wait statement will immediately end your current time slice and allow another task to start earlier. Remember that there are bottlenecks when talking to sensors and so on that mean that a while loop can pole them far more frequently than they can update.

4) If you have a critical section you can surround it with HogCPU/ReleaseCPU. Do this ONLY when it is critical. For example if you need to swap two values that are used by a parallel task and want to make sure that the other task does not look at the values while they are changing you should hog the cpu, swap the value and then release the cpu.

5) Don't go task crazy. You should have a good reason for doing things in parallel.

6) Even if the only task you define is task main() there are actually multiple tasks running. The drivers for the various sensors and other hardware elements have background tasks that poll the hardware and update things. That is how the values in the sensor[] array get updated and how changes you make to the motor[] array actuall propagate to the motors.

You should notice that the main task in my template polls the game controllers so you will not have to do that in any other task. The "drive" task can just look at the "joystick" structure without calling getJoystickSettings() becuase it is being done by "main" in the background.

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum