Log in

View Full Version : [FTC]: NXT Display Code


gdo
02-02-2009, 17:52
I was working on an autonomous program chooser to work locally on the NXT. the problem lies when you use the #included "JoystickDrive.c" command (which we have to use...) there is a included file in this drive to display information about battery voltage and important information like that. The problem is that it covers the screen when I want to display information over it for my program selecter.

Here's the code: (BTW, I removed user specific code to make the post not too long, all it did was use the strings and user functions to compile the wanted autonomous).




#include "JoystickDriver.c" //Include file to "handle" the Bluetooth messages.

int nAlliance = 0;
int nStart = 0;
int nScore = 0;
string sAlliance = "Red";
string sStart = "Floor";
string sScore = "12' Goal";


int nLeftButton = 0;
int nRightButton = 0;
int nEnterButton = 0;


void AutonomousChooser()
{
// Place code here to sinitialize servos to starting positions.
// Sensors are automatically configured and setup by ROBOTC. They may need a brief time to stabilize.


//////////////////////////////////////////////////////////////////////////////////////////////////////
//
// "Hi-jack" buttons for user program control.
//
nNxtButtonTask = -2; // Grab control of the buttons. '-3' is invalid for task, so no task will be
// executed when a button is pressed.

//
// Note: program cannot be terminated if we hijack the 'exit' button. So there has to be an escape sequence
// that will return buttons to system control! We'll use a triple click
//
nNxtExitClicks = 2; // Double clicking EXIT button will terminate program
//
// Do nothing. Just keep waiting
//

while (nEnterButton != 4)
{

TButtons nBtn;
while (true) // wait for button press
{
nBtn = nNxtButtonPressed;
if (nBtn != -1)
break;
}

switch (nBtn)
{
case kLeftButton: ++nLeftButton; break;
case kRightButton: ++nRightButton; break;
case kEnterButton: ++nEnterButton; break;
}

PlaySoundFile("! Click.rso");
nxtDisplayTextLine(0, "Alliance:" );

nxtDisplayTextLine(2, "Starting:" );

nxtDisplayTextLine(4, "Score:" );

nxtDisplayTextLine(6, "Double Click EXIT");
nxtDisplayTextLine(7, " to end program ");

if(nEnterButton == 0)
{
nRightButton = 0;
nLeftButton = 0;
nEnterButton = 0;
}
if(nEnterButton == 1)
{
nAlliance = abs(nLeftButton - nRightButton);
if((nAlliance == 0) || (nAlliance == 2))
{
sAlliance = "Red";
nxtDisplayTextLine(1, "%s", sAlliance); //
nRightButton = 0;
nLeftButton = 0;
}
if(nAlliance == 1)
{
sAlliance = "Blue";
nxtDisplayTextLine(1, "%s", sAlliance); //
}
}
if (nEnterButton == 2)
{
nStart = abs(nLeftButton - nRightButton);
if((nStart == 0) || (nStart == 2))
{
sStart = "Floor";
nxtDisplayTextLine(3, "%s", sStart); //
nRightButton = 0;
nLeftButton = 0;
}
if(nStart == 1)
{
sStart = "Ramp";
nxtDisplayTextLine(3, "%s", sStart); //
}
}
if (nEnterButton == 3)
{
nScore = abs(nLeftButton - nRightButton);
if((nScore == 0) || (nScore == 2))
{
sScore = "12' Goal";
nxtDisplayTextLine(5, "%s", sScore); //
nRightButton = 0;
nLeftButton = 0;
}
if(nScore == 1)
{
sScore = "20' Goal";
nxtDisplayTextLine(5, "%s", sScore); //
}
}
while (true) // wait for button release
{
nBtn = nNxtButtonPressed;
if (nBtn == -1)
break;
}
}
return;
}


I was just wonder if it would be legal to edit the JoystickDrive.c file to remove the dianogstic code or is there some way to clear the screen of this data for as long as I am using this routine. I tried using the EraseDisplay routine, but it doesn't erase all lines, any ideas or suggestions?

Thanks in advance guys!
~GDO, Team Unlimited (FTC #1)

This routine does work 100% without the template right now, so if any one has any questions about it or wants to use it, I will explain it and show you the complete code.

Inside the "JoystickDriver.c" file, the problem source is here:


task displayDiagnostics()
{
string sFileName;

getUserControlProgram(sFileName);
nxtDisplayTextLine(6, "Teleop FileName:");
nxtDisplayTextLine(7, sFileName);
bNxtLCDStatusDisplay = true;
while (true)
{
if (bDisplayDiagnostics)
{
getJoystickSettings(joystick); //Update variables with current joystick values

if (joystick.StopPgm)
nxtDisplayCenteredTextLine(1, "Wait for Start");
else if (joystick.UserMode)
nxtDisplayCenteredTextLine(1, "TeleOp Running");
else
nxtDisplayCenteredTextLine(1, "Auton Running");

if ( externalBatteryAvg < 0)
nxtDisplayTextLine(3, "Ext Batt: OFF"); //External battery is off or not connected
else
nxtDisplayTextLine(3, "Ext Batt:%4.1f V", externalBatteryAvg / (float) 1000);

nxtDisplayTextLine(4, "NXT Batt:%4.1f V", nAvgBatteryLevel / (float) 1000); // Display NXT Battery Voltage

nxtDisplayTextLine(5, "FMS Msgs: %d", nMessageCount); // Display Count of FMS messages
}

wait1Msec(200);
}
}


From what I see, its purely cosmetic and shouldn't interfer w/ anything if removed.

gdo
02-02-2009, 19:14
I just figured it out...

I case anyone is interested in using this code in competition add this to your code:


task main()
{
initializeRobot();

eraseDisplay();
bDisplayDiagnostics = false;
AutonomousChooser();
bDisplayDiagnostics = true;

waitForStart(); // Wait for the beginning of autonomous phase.

//YOUR CODE HERE

e.g.

if(sAlliance == "Blue")
{
//Blue ALLIANCE
if((sStart == "Floor") & (sScore == "12' Goal"))
{
// SCORE in the 12"
// GATHER from the Near Dispenser
// START from the Floor
}
}
}


just an example. Also, the AutonomousChooser was updated to this:



int nAlliance = 0;
int nStart = 0;
int nScore = 0;
string sAlliance = "Red";
string sStart = "Floor";
string sScore = "12' Goal";

void AutonomousChooser ()
{
//////////////////////////////////////////////////////////////////////////////////////////////////////
//
// "Hi-jack" buttons for user program control.
//
nNxtButtonTask = -2; // Grab control of the buttons. '-3' is invalid for task, so no task will be
// executed when a button is pressed.

//
// Note: program cannot be terminated if we hijack the 'exit' button. So there has to be an escape sequence
// that will return buttons to system control! We'll use a triple click
//
nNxtExitClicks = 2; // Double clicking EXIT button will terminate program
//
// Do nothing. Just keep waiting
//

while (nEnterButton != 4)
{
TButtons nBtn;
while (true) // wait for button press
{
nBtn = nNxtButtonPressed;
if (nBtn != -1)
break;
}

switch (nBtn)
{
case kLeftButton: ++nLeftButton; break;
case kRightButton: ++nRightButton; break;
case kEnterButton: ++nEnterButton; break;
}

PlaySoundFile("! Click.rso");
nxtDisplayTextLine(0, "Alliance:" );
nxtDisplayTextLine(2, "Starting:" );
nxtDisplayTextLine(4, "Score:" );
nxtDisplayTextLine(6, "Double Click EXIT");
nxtDisplayTextLine(7, " to end program ");

if(nEnterButton == 0)
{
nRightButton = 0;
nLeftButton = 0;
nEnterButton = 0;
}
if(nEnterButton == 1)
{
nAlliance = abs(nLeftButton - nRightButton);
nxtDisplayTextLine(3, " ");
nxtDisplayTextLine(5, " ");
if((nAlliance == 0) || (nAlliance == 2))
{
sAlliance = "Red";
nxtDisplayTextLine(1, "%s", sAlliance); //
nRightButton = 0;
nLeftButton = 0;
}
if(nAlliance == 1)
{
sAlliance = "Blue";
nxtDisplayTextLine(1, "%s", sAlliance); //
}
}
if (nEnterButton == 2)
{
nStart = abs(nLeftButton - nRightButton);
if((nStart == 0) || (nStart == 2))
{
sStart = "Floor";
nxtDisplayTextLine(3, "%s", sStart); //
nRightButton = 0;
nLeftButton = 0;
}
if(nStart == 1)
{
sStart = "Ramp";
nxtDisplayTextLine(3, "%s", sStart); //
}
}
if (nEnterButton == 3)
{
nScore = abs(nLeftButton - nRightButton);
if((nScore == 0) || (nScore == 2))
{
sScore = "12' Goal";
nxtDisplayTextLine(5, "%s", sScore); //
nRightButton = 0;
nLeftButton = 0;
}
if(nScore == 1)
{
sScore = "20' Goal";
nxtDisplayTextLine(5, "%s", sScore); //
}
}
while (true) // wait for button release
{
nBtn = nNxtButtonPressed;
if (nBtn == -1)
break;
}
}
}


I will try to get this all comment out ASAP and i'll answer any questions on it in the mean time. :)

Michael Coleman
02-02-2009, 23:39
Issue #1
The software templates are mandatory for FTC competitions. Robots that don't display the diagnostics may fail software inspection.

Issue #2
The Field Technical Advisor (FTA) at a competition is responsible for diagnosing problems when robots behave unexpectedly during competitions. Unexpected behavior can be caused by the robot or the Field Control System. The diagnostic information written to the NXT enables the FTA to quickly eliminate many of the common robot problems. Robots that don't display the diagnostics could be at a disadvantage when there is unexpected robot behavior during a match.

For example, a robot doesn't start Autonomous or doesn't move in the Tele-op portion of a match. The robot is still in the starting position near the field wall and the FTA can see the NXT display. [This is a very common situation.] If the robot is using the ROBOTC template the FTA can check for the following on the NXT display:

- Is the NXT enabled or disabled?
- Does the NXT's internal battery have sufficient voltage?
- Is the external battery pack powering the HiTechnic controllers turned on and have sufficient voltage?
- Is the NXT receiving Bluetooth packets?
- What is the name of the Tele-op program?

If the NXT doesn't display the expected diagnostic information, the door is open for the FTA to declare that the unexpected robot behavior is likely a robot failure since it isn't programmed using the mandatory template. Or worse, the robot should not be allowed to participate in a match since it shouldn't have passed software inspection.

Suggestion:
Teams could write their own information to the NXT display during software development and testing. Once the software is competition ready, it is in the team's best interest to use the mandatory template. The template minimizes the risk of failing software inspection and provides the FTA with valuable information when diagnosing unexpected robot behavior during a match.

Michael

jbbjjbt
03-02-2009, 07:35
Currently we are using LabView rathar than RobotC.

But we write on the NXT screen to allow us to choose between red and blue and ramp and floor. We also write the Voltage form the battery using Phil's great program. All of this easily fits under the information that the template writes on the screen. We just use the two lines on the bottom of the screen.

Michael Coleman
03-02-2009, 09:36
Jon is correct. The NXT-G and LabVIEW templates display less diagnostic information than the ROBOTC template. This leaves space at the bottom of the NXT display for team diagnostics.

Michael

gdo
03-02-2009, 16:51
it disables the display for about 10 seconds before the match begins (before it should recieve a message from the FMS). then right after that it re-enables the diagnostic software. so for a total of 10 seconds before the round even begins the diagnostic software is running but not displaying.

dickswan
05-02-2009, 10:16
Personally I think what you've done is fine. [I wrote the "joystickDriver.c" code so I have some knowledge of this.]

But as Michael Coleman has commented, it's up to the local competititon "Field Adminstrator" to make the call.

If your chooser code only displays to the screen before you get to the field, then I think you'd probably be OK.

Another alternative that you might want to consider is having a separate program to select which of the four choices. It could write this to a file on the NXT -- perhaps only containing a single character. Then your autonomous program could read this file and make the appropriate decision. If you want help with this, email me directly (dickswan@sbcglobal.net) and I'll send you more details.

NOTE: the diagnostic information on the NXT screen for the Field Management system is somewhat of a pain. This is information that the Field Management System could interrogate from the NXT (via Bluetooth) and display on the FMS. However, this was too big a change to make late in the season and instead this information was added to the LCD display.