Revised Joystick Driver for RobotC

Summary: adds element "joystick.Connected" to the joystick control structure 

The Techno Guards use RobotC to program their robots. 

One of the issues that we noted in the way that RobotC handles joystick communication is that there's no notification if communication is lost.  To that end, we initially tried to watch the received message counter in the main program and decided that wasn't working well.

Then we realized that the ability to do the same thing is already in the driver by just adding a NoMessageCounter which we monitor, and whenever the count goes over 200 (around 800msec) we indicate that the robot is not connected, the next time we get a message from the joysticks, it goes back to connected againl

So, now our main task watches to see if the joysticks are connected. If so, the joystick control is run, if not, the robot is stopped safely:

#include "ConnectedJoystickDriver"

void ControlRobot()
{
  // basic control stuff goes here
}

void StopRobot()
{
  // Loss of communication stop code goes here
}

task main()
{
  waitForStart();

  while(true)
  {
    if(joystick.Connected)
    {
      ControlRobot();
    } else {
      StopRobot();
    }
  }
}

 

We've attached the driver below.

Note that this doesn't handle any kind of loss of communication from the NXT brain to the Tetrix controllers... we know that this is another problem that occurs too!

Also note that this is not sanctioned or supported by FTC, RobotC, or anyone else. This is without warranty of any kind - and you use it at your own risk. That being said, if you find a problem with it, let us know and we'll try to fix it!

AttachmentSize
ConnectedJoystickDriver.zip3.85 KB