Quote:
Originally Posted by Random Dude
It's actually not specifically a samantha issue. The same thing can (and does) happen over bluetooth, and even potentially direct USB tether (if one were to pull the cable out). The joystick.c template fails to get any packets from the controller, and just assumes the values should remain the same. (instead of entering a failsafe mode)
|
It doesn't need to be in the template. You can write your own and include it in your code. An example that could work is below.
Note that if the Samantha does keep sending the last packet, this won't work. But do we know for sure this is the case?
There's another problem I've seen occasionally that looks like a Samantha issue but isn't. If the I2C bus disconnects for a moment, it doesn't always re-attach correctly and thus the last message sent to the is continuously active. RobotC doesn't seem to have a means to verify and/or reset communication to the controllers programatically. That would be something that would REALLY help the issue.
Part of the complaining about Samantha is probably valid, but often it's the "newest thing" syndrome. When something doesn't work, the automatic blame goes to the newest thing. Even if the real issue has been there all along, or is something else.
Here's an idea for comm loss monitor code:
Code:
#include "JoystickDriver.c"
int nLastMessageCount = -1;
// This variable is used to keep a comparison copy of the message count
int nLastSysTime = 32767;
// this variable is used with the sSysTime system timer variable
// to create a pseudo up time counter. Because it wraps automatically,
// that timer has an issue with a couple specific times. But since
// precision accuracy isn't required, it will still work for this purpose
bool CommOK()
{
if (nLastSysTime < nSysTime) nLastSysTime = nSysTime;
// The previous line handles the timer wraparound issue
// in this one case, the delay before notification
// goes to a max of 3 Seconds if there's no comm.
// I could have used a timer if we need the accuracy, but
// there's only 4 of them and this way I don't use one up.
// the variable ntotalMessageCount is defined and updated in
// the joystickDriver.c file
if (nLastMessageCount != ntotalMessageCount) // has there been a new comm?
{
nLastMessageCount = ntotalMessageCount; // update the comparison comm ID
nLastSysTime = nSysTime; // update the comparison time
} else { // there has not been a new message
if (nSysTime > nLastSysTime + 1500) return false;
// the previous line says that if our pseudo timer gets
// to a second and a half, we've had no messages, and thus
// comm is not OK.
}
return true; // if we get to here without returning false, comm is OK
}
task main()
{
while(true)
{
while (!CommOK())
{
// Handle Comm (joystick message) failures here.
// might be stuff like "motor[motorA] = 0;"
wait1Msec(1);
}
wait1Msec(1);
}
}