Ok, last post for tonight. I ported the code to ConVEX, very easy, almost line for line identical except for the difference in API. I ran this code for 60 minutes with no errors (not surprised but somewhat relieved about this). Setup was identical, joystick tethered to cortex and powered through the USB cable, cortex powered from my bench supply, the same setup I use for 95% of my testing.
I then went back to the PROS version, two more errors within 15 minutes of running, always joystick button 8 right.
(which now I think about it is not unexpected, you test for joystick right after everything else and that will always take precedence. What probably happens is that all bits are set to ‘1’ or something like that).
So my conclusion is that using this example code PROS has a bug when reading the joystick.
Other software may not experience this bug, in this code the buttons are latched, most student code does not do this and a brief 20mS blip in a joystick button may go unnoticed. The exact timing and delays in this code may be the cause, only Purdue can debug this further, it’s not part of my job description.
Your code is different, you may not use button 8R, you may check it more/less often. Bugs like this are very hard to find, it may the 20mS delay used, it may be the order that the joystick is read (left, down, right). I have some theories but PROS is a black box library that would take me too long to debug.
FYI, comparison of the PROS and ConVEX code (just a small part, with some extra stuff I added for debug)
PROS
<< snip >>
switch (digitalRead(12))
{
//running motors mode
case true:
if (lcdReadButtons(uart1) == LCD_BTN_LEFT && !lcdLeftPressed)
{
output = -127;
lcdLeftPressed = true;
lcdSetText(uart1, 1, "LL");
}
else if (lcdReadButtons(uart1) != LCD_BTN_LEFT) lcdLeftPressed = false;
if (lcdReadButtons(uart1) == LCD_BTN_CENTER && !lcdCenterPressed)
{
output = 0;
lcdCenterPressed = false;
lcdSetText(uart1, 1, "LC");
}
else if (lcdReadButtons(uart1) != LCD_BTN_CENTER) lcdCenterPressed = false;
if (lcdReadButtons(uart1) == LCD_BTN_RIGHT && !lcdRightPressed)
{
output = 127;
lcdRightPressed = true;
lcdSetText(uart1, 1, "LR");
}
else if (lcdReadButtons(uart1) != LCD_BTN_RIGHT) lcdRightPressed = false;
if (joystickGetDigital(1, 8, JOY_LEFT) && !joy8LPressed)
{
output = -127;
joy8LPressed = true;
lcdSetText(uart1, 1, "JL");
}
else if (!joystickGetDigital(1, 8, JOY_LEFT)) joy8LPressed = false;
<< snip >>
ConVEX
<< snip >>
switch (vexDigitalPinGet(kVexDigital_12))
{
//running motors mode
case true:
if (vexLcdButtonGet(VEX_LCD_DISPLAY_1) == kLcdButtonLeft && !lcdLeftPressed)
{
output = -127;
lcdLeftPressed = true;
vexLcdSet( VEX_LCD_DISPLAY_1, VEX_LCD_LINE_1, "LL");
}
else if (vexLcdButtonGet(VEX_LCD_DISPLAY_1) != kLcdButtonLeft) lcdLeftPressed = false;
if (vexLcdButtonGet(VEX_LCD_DISPLAY_1) == kLcdButtonCenter && !lcdCenterPressed)
{
output = 0;
lcdCenterPressed = false;
vexLcdSet( VEX_LCD_DISPLAY_1, VEX_LCD_LINE_1, "LC");
}
else if (vexLcdButtonGet(VEX_LCD_DISPLAY_1) != kLcdButtonCenter) lcdCenterPressed = false;
if (vexLcdButtonGet(VEX_LCD_DISPLAY_1) == kLcdButtonRight && !lcdRightPressed)
{
output = 127;
lcdRightPressed = true;
vexLcdSet( VEX_LCD_DISPLAY_1, VEX_LCD_LINE_1, "LR");
}
else if (vexLcdButtonGet(VEX_LCD_DISPLAY_1) != kLcdButtonRight) lcdRightPressed = false;
if (vexControllerGet( Btn8L ) && !joy8LPressed)
{
output = -127;
joy8LPressed = true;
vexLcdSet( VEX_LCD_DISPLAY_1, VEX_LCD_LINE_1, "JL");
}
else if (!vexControllerGet( Btn8L )) joy8LPressed = false;
<< snip >>