View unanswered posts | View active topics It is currently Thu May 23, 2013 7:14 am






Reply to topic  [ 15 posts ] 
Exception Violation with joystick 
Author Message
Rookie

Joined: Sat Mar 12, 2011 12:22 pm
Posts: 17
Post Exception Violation with joystick
I am having a problem. When ever I press button 6 on my joystick the motors will continue to run even after I stopped the program (The program is a car). There is also popping up an error message on the PC:

Byte Code Interpreter Exception:
Program Slot: 0, Task ID: main[0]
Error at PC: Sub; joy1Btn+0x0017
Task PC: Sub: joy1Btn+0x0017
TaskState: 'Exception'
Exception Type: 'Shift value Out of range(14)


I'm using this program:

Main Task (Steering)
Code:
#pragma config(Sensor, S2,     S2,                  sensorTouch)
#pragma config(Sensor, S4,     S4,                  sensorTouch)
#pragma config(Motor,  motorB,          motorB,        tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"
#include "driving.c"

void turn_left()
{
  if(SensorValue[S2] == 0)
  {
    motor[motorB] = 100;
  }
  else
  {
    motor[motorB] = 0;
  }
}

void turn_right()
{
  if(SensorValue[S4] == 0)
  {
    motor[motorB] = -100;
  }
  else
  {
    motor[motorB] = 0;
  }
}

task main ()
{
  StartTask(driving);
  while (true)
  {
    getJoystickSettings (joystick);
    if (joy1Btn(1))
    {
      turn_left();
    }
    else
    {
      bFloatDuringInactiveMotorPWM = true;
      motor[motorB] = 0;
    }
    if (joy1Btn(3))
    {
      turn_right();
    }
    else
    {
      bFloatDuringInactiveMotorPWM = true;
      motor[motorB] = 0;
    }
  }
}


Driving:
Code:
#include "motormux-lib.c"


task driving()
{
  int nSpeed;
  SensorType[S3] = sensorI2CCustom;
  while (true)
  {
    if (joy1Btn(5))
    {
      nSpeed = 255;
      mmControl(S3, 0xB4, 0, mmReverse, nSpeed);
      mmControl(S3, 0xB4, 1, mmReverse, nSpeed);
      mmControl(S3, 0xB4, 3, mmForward, nSpeed);
    }
    else
    {
      if (joy1Btn(6))
      {
        nSpeed = 255;
        mmControl(S3, 0xB4, 0, mmForward, nSpeed);
        mmControl(S3, 0xB4, 1, mmForward, nSpeed);
        mmControl(S3, 0xB4, 3, mmReverse, nSpeed);
      }
      else
      {
        nSpeed = 0;
        mmControl(S3, 0xB4, 0, mmFloat, nSpeed);
        mmControl(S3, 0xB4, 1, mmFloat, nSpeed);
        mmControl(S3, 0xB4, 3, mmFloat, nSpeed);
      }
    }
  }
}


It's in the driving program that it goes wrong. In the "Errors" at the bottom of the screen it says:

*Warning*:Use 'inline' to avoid possible simultaneous variable memory access conflicts for subroutine 'joy1Btn' called from multiple tasks 'driving' and 'main'?
So now I've actually got a clue of what is wrong. It's when I press "joy1Btn 6" that something is in conflict. What could solve this problem?


Thu Jun 09, 2011 3:48 pm
Profile
Rookie

Joined: Sat Mar 12, 2011 12:22 pm
Posts: 17
Post Re: Exception Violation with joystick
I really really need this thing solved asap.

I have tried putting the
Code:
#define getJoystickSettings(joystick)    memcpy(joystick, joystickCopy, sizeof(joystick))
bool joy1Btn(int btn)
{   
  return ((joystick.joy1_Buttons & (1 << (btn - 1))) != 0); 
}

anywhere in the program, but then i'll just get even more error and warning messages. As the program is now, every joystick command is conflicting with each other. I know using the 'inline' variable will solve it, But I don't know how.

Please help me


Fri Jun 10, 2011 9:56 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 2864
Location: Rotterdam, The Netherlands
Post Re: Exception Violation with joystick
Send a mail to support@robotc.net if you need a quick answer.

- Xander

_________________
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)

| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Jun 10, 2011 1:14 pm
Profile WWW
Site Admin
Site Admin

Joined: Mon Jun 08, 2009 4:50 pm
Posts: 70
Post Re: Exception Violation with joystick
Hi Flagstang,

Which I2C sensor are you using? Also, at first glance, it seems that you may have multiple tasks fighting for control of the motors, as well as some questionable "if/else" logic where both buttons 1 and 2 are controlling motor B.

Perhaps you could explain better what it is that you are trying to do and we could try and find a solution.

_________________
Bence Feher

Undergraduate Intern - NREC, Robotics Academy
ROBOTC - Testing/Documentation/Developer

Computer Science, Japanese, East Asian Studies
University of Pittsburgh, Konan University 甲南大学


Mon Jun 13, 2011 10:36 am
Profile
Rookie

Joined: Sat Mar 12, 2011 12:22 pm
Posts: 17
Post Re: Exception Violation with joystick
I am using the motormux purchased at mindsensors.com: http://mindsensors.com/index.php?module ... PAGE_id=58
As I've said before, i've built a car. I just realized that this program is blocking it self, just like you said. I have now made a new statement.

OK the main program is this one (called Ferrari Enzo.c):

Code:
#pragma config(Sensor, S2,     S2,                  sensorTouch)
#pragma config(Sensor, S4,     S4,                  sensorTouch)
#pragma config(Motor,  motorB,          motorB,        tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"
#include "driving.c"

void turn_left()
{
  if(SensorValue[S2] == 0)
  {
    motor[motorB] = 70;
  }
}


void turn_right()
{
  if(SensorValue[S4] == 0)
  {
    motor[motorB] = -70;
  }
}


task main ()
{
  StartTask(driving);
  while (true)
  {
    getJoystickSettings (joystick);
    if (joy1Btn(1))
    {
      turn_left();
    }
    else
    {
      getJoystickSettings (joystick);
      if (joy1Btn(3))
      {
        turn_right();
      }
      else
      {
        bFloatDuringInactiveMotorPWM = false;
        motor[motorB] = 0;
      }
    }
  }
}


I have a sensor at each side of the front wheels. When either one of the sensors are pressed (only 1 can be pressed at a time) the motor turning the wheels, will stop.
That is the "void" stuff before the main task

Next I have "task main", where as the key here is that when I press a button on the joystick the wheels will turn to the corresponding side. If no button is pressed the wheels will not turn. (Well in this program they will turn faster, the faster you release the button and that's also a problem)
Even If I take out the "#include driving.c" and "start task(driving)" the steering wheels would still turn this oddly.


So now to this driving program. The file is called "Driving.c" and it works fine if I put it in a seperate program

Code:
#include "motormux-lib.c"

task driving()
{
  int nSpeed;
  SensorType[S3] = sensorI2CCustom;
  while (true)
  {
    if (nNxtButtonPressed == 1)
    {
      nSpeed = 255;
      mmControl(S3, 0xB4, 0, mmReverse, nSpeed);
      mmControl(S3, 0xB4, 1, mmReverse, nSpeed);
      mmControl(S3, 0xB4, 3, mmForward, nSpeed);
    }
    else
    {
    if (nNxtButtonPressed == 3)
      {
        nSpeed = 255;
        mmControl(S3, 0xB4, 0, mmForward, nSpeed);
        mmControl(S3, 0xB4, 1, mmForward, nSpeed);
        mmControl(S3, 0xB4, 3, mmReverse, nSpeed);
      }
      else
      {
        nSpeed = 0;
        mmControl(S3, 0xB4, 0, mmFloat, nSpeed);
        mmControl(S3, 0xB4, 1, mmFloat, nSpeed);
        mmControl(S3, 0xB4, 3, mmFloat, nSpeed);
      }
    }
  }
}


The statement is the same as the one before; if one button is pressed all the motors (well only 3, since 1 of the IC's doesn't work - I think I burned it with too much current :P ) will go that direction (forward or backward - it depends on the wiring on the car).
The thing that doesn't work here is when I assign the "if (NXTbtn)" to an "if (joy1btn). Then the steering still works, but when I press a driving button on the joystic the program will terminate it self and leave the motors running, while giving me a pop-up-warning. Not very handy right?

All the stuff that isn't working is the joystick mapping. Something is interfering each other within the program and I dunno what it could be


Mon Jun 13, 2011 1:05 pm
Profile
Site Admin
Site Admin

Joined: Mon Jun 08, 2009 4:50 pm
Posts: 70
Post Re: Exception Violation with joystick
Hmmm. There is one thing that immediately pops out to me: Both tasks 'main' and 'driving' want to give the motors commands. While this may not be the cause of your issue, it may lead to the cause if you simplify the code down to one task.

What you're describing to me seems like a classic case of multitasking messing things up. I'd write it all as one task (task main) with functions.

Is there any way that you could put all of your code into task main? Is there any particular reason why you are using multiple tasks? It's silly, but multitasking really does mess with your program in ways that makes no sense to anybody except the compiler.

If you need help condensing your code down to a single task let me know. Sorry that I can't help much more but I think that this is the 1st step towards getting it to work. I'll see if I have a mindsensors MUX around here somewhere and run your code.

_________________
Bence Feher

Undergraduate Intern - NREC, Robotics Academy
ROBOTC - Testing/Documentation/Developer

Computer Science, Japanese, East Asian Studies
University of Pittsburgh, Konan University 甲南大学


Wed Jun 15, 2011 10:29 am
Profile
Rookie

Joined: Sat Mar 12, 2011 12:22 pm
Posts: 17
Post Re: Exception Violation with joystick
Funny you say that. I have tried putting it all in the same code, but then nothing works. Actually this is what I have tried:

Code:
#pragma config(Sensor, S2,     S2,                  sensorTouch)
#pragma config(Sensor, S4,     S4,                  sensorTouch)
#pragma config(Motor,  motorB,          motorB,        tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"
#include "motormux-lib.c"


void turn_left()
{
  if(SensorValue[S2] == 0)
  {
    motor[motorB] = 70;
  }
}


void turn_right()
{
  if(SensorValue[S4] == 0)
  {
    motor[motorB] = -70;
  }
}


task main ()
{
  int nSpeed;
  SensorType[S3] = sensorI2CCustom;
  while (true)
  {
    getJoystickSettings (joystick);
    if (joy1Btn(1))
    {
      turn_left();
    }
    else
    {
      if (joy1Btn(3))
      {
        turn_right();
      }
      else
      {
        bFloatDuringInactiveMotorPWM = false;
        motor[motorB] = 0;
      }
    }
    if (joy1Btn(5))
    {
      nSpeed = 255;
      mmControl(S3, 0xB4, 0, mmReverse, nSpeed);
      mmControl(S3, 0xB4, 1, mmReverse, nSpeed);
      mmControl(S3, 0xB4, 3, mmForward, nSpeed);
    }
    else
    {
    if (joy1Btn(6))
      {
        nSpeed = 255;
        mmControl(S3, 0xB4, 0, mmForward, nSpeed);
        mmControl(S3, 0xB4, 1, mmForward, nSpeed);
        mmControl(S3, 0xB4, 3, mmReverse, nSpeed);
      }
      else
      {
        nSpeed = 0;
        mmControl(S3, 0xB4, 0, mmFloat, nSpeed);
        mmControl(S3, 0xB4, 1, mmFloat, nSpeed);
        mmControl(S3, 0xB4, 3, mmFloat, nSpeed);
      }
    }
  }
}


As I said, it won't work. At least not with the joystick commands. When I replace the joy1Btn with nNXTbuttonpressed everything works fine. Unfortunately, only one button can be pressed on the NXt at a time, so that's a no-go.
And I'm using the TETRIX+NXT thing by the way - whatever that is. I have to use this or the joystick won't work.

I think adding some more stuff about the joystick programming in the help file would help out a lot. There is actually only 2 files that can help, and those are very very slim with info on the joystick programming....


Wed Jun 15, 2011 11:00 am
Profile
Rookie

Joined: Sat Mar 12, 2011 12:22 pm
Posts: 17
Post Re: Exception Violation with joystick
Are there no solutions to this problem? I still don't know How to program the joystick correctly


Mon Jun 20, 2011 10:51 am
Profile
Site Admin
Site Admin

Joined: Mon Jun 08, 2009 4:50 pm
Posts: 70
Post Re: Exception Violation with joystick
In your example with just task main (no multitasking) what didn't work about it? Did you still get the byte-code exception?

If you look closely at your if/else blocks there is some weird and possibly unwanted nesting going on that doesn't seem to match what I've come to understand that you want the program to do.

Try this instead,

Code:
#pragma config(Sensor, S2,     S2,                  sensorTouch)
#pragma config(Sensor, S4,     S4,                  sensorTouch)
#pragma config(Motor,  motorB,          motorB,        tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"
#include "motormux-lib.c"



task main ()
{
  int nSpeed;
  SensorType[S3] = sensorI2CCustom;
 
  while (true)
  {
    getJoystickSettings (joystick);
   
   
    // This group is tied together------------------------------
    if (joy1Btn(1) && (SensorValue[S2] == 0))               // |
    {                                                       // |
      motor[motorB] = 70;                                   // |
    }                                                       // |
    else if (joy1Btn(3) && (SensorValue[S4] == 0))          // |
    {                                                       // |
      motor[motorB] = -70;                                  // |
    }                                                       // |
    else                                                    // |
    {                                                       // |
      bFloatDuringInactiveMotorPWM = false;                 // |
      motor[motorB] = 0;                                    // |
    }                                                       // |
    //----------------------------------------------------------
   
   
   
    // This group is also tied together-------------------------
    if (joy1Btn(5))                                         // |
    {                                                       // |
      nSpeed = 255;                                         // |
      mmControl(S3, 0xB4, 0, mmReverse, nSpeed);            // |
      mmControl(S3, 0xB4, 1, mmReverse, nSpeed);            // |
      mmControl(S3, 0xB4, 3, mmForward, nSpeed);            // |
    }                                                       // |
    else if (joy1Btn(6))                                    // |
    {                                                       // |
      nSpeed = 255;                                         // |
      mmControl(S3, 0xB4, 0, mmForward, nSpeed);            // |
      mmControl(S3, 0xB4, 1, mmForward, nSpeed);            // |
      mmControl(S3, 0xB4, 3, mmReverse, nSpeed);            // |
    }                                                       // |
    else                                                    // |
    {                                                       // |
      nSpeed = 0;                                           // |
      mmControl(S3, 0xB4, 0, mmFloat, nSpeed);              // |
      mmControl(S3, 0xB4, 1, mmFloat, nSpeed);              // |
      mmControl(S3, 0xB4, 3, mmFloat, nSpeed);              // |
    }                                                       // |
    //----------------------------------------------------------
  }
}


Please compare our if/else blocks to notice the key difference between them. Also, since I don't have a mindsensors MUX, I wasn't able to run this program so let me know how it goes. Again, if you didn't get the byte-code error when you combined the program then YES the problem was with multitasking! You said that the code didn't work as you wanted and I have a hunch that it had to do with how you nested the if/else/else if blocks.


Hope this helps, let me know what happens,

_________________
Bence Feher

Undergraduate Intern - NREC, Robotics Academy
ROBOTC - Testing/Documentation/Developer

Computer Science, Japanese, East Asian Studies
University of Pittsburgh, Konan University 甲南大学


Wed Jun 22, 2011 10:04 am
Profile
Rookie

Joined: Sat Mar 12, 2011 12:22 pm
Posts: 17
Post Re: Exception Violation with joystick
Thank you very much for your reply. I didn't know you could put "if" and "else" in the same line, so maybe that's where it went wrong?

It actually works better now. The MUX controller works perfectly; when you press button 5 it goes forward, and when you press button 6 it goes backwards.
This works at the same time with the steering, allowing me to hold down more buttons at the same time.

But actually the steering doesn't work yet. When I press eiter button 1 or 3, motorB will run, but it keeps running when I release one of the buttons, AND when it hits the sensor that should stop the motor going in that direction. I have also tried putting in the "void" command again, but that didn't change anything.

At least now, we won't have to worry about the MUX sensor anymore :wink:


Wed Jun 22, 2011 10:31 am
Profile
Site Admin
Site Admin

Joined: Mon Jun 08, 2009 4:50 pm
Posts: 70
Post Re: Exception Violation with joystick
I'm happy to hear that the error has disappeared. As far as the motor not stopping, it stops when I run just that bit of code. Perhaps the touch sensors S2 and S4 are in different ports or are flipped? I wrote the if() condition to check a button and a touch sensor together with the logical AND operator (&&). So Joy1Btn(1) and S2 are checked together and so are Joy1Btn(3) and S4. Perhaps it should be Joy1Btn(1) with S4, and Joy1Btn(3) and S2?

Check that out because I didn't know the physical layout of your robot and I may have switched them in the code.

_________________
Bence Feher

Undergraduate Intern - NREC, Robotics Academy
ROBOTC - Testing/Documentation/Developer

Computer Science, Japanese, East Asian Studies
University of Pittsburgh, Konan University 甲南大学


Thu Jun 23, 2011 10:17 am
Profile
Rookie

Joined: Sat Mar 12, 2011 12:22 pm
Posts: 17
Post Re: Exception Violation with joystick
Well if you exchange the sensor ports in the program the motor will turn at 100% speed instantly and not stop again.

I have tried running just that bit of code like you:

Code:
#pragma config(Sensor, S2,     S2,                  sensorTouch)
#pragma config(Sensor, S4,     S4,                  sensorTouch)
#pragma config(Motor,  motorB,          motorB,        tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"

task main ()
{
  while (true)
  {
    getJoystickSettings (joystick);
   
   

    // This group is tied together------------------------------
    if (joy1Btn(1) && (SensorValue[S2] == 0))               // |
    {                                                       // |
      motor[motorB] = 70;                                   // |
    }                                                       // |
    else if (joy1Btn(3) && (SensorValue[S4] == 0))          // |
    {                                                       // |
      motor[motorB] = -70;                                  // |
    }                                                       // |
    else                                                    // |
    {                                                       // |
      bFloatDuringInactiveMotorPWM = false;                 // |
      motor[motorB] = 0;                                    // |
    }                                                       // |
    //----------------------------------------------------------
  }
}


With the above code, the motor will act just like before; Hitting a button will make the motor turn and not stop when hitting the sensor. The speed of the motor depends on how quickly you release the button again. And that' sounds wierd to my ears. .... Maybe I should post a video?


Thu Jun 23, 2011 3:13 pm
Profile
Site Admin
Site Admin

Joined: Mon Jun 08, 2009 4:50 pm
Posts: 70
Post Re: Exception Violation with joystick
This is starting to sound like a hardware problem. It's difficult to debug the program without your robot to test on, but the code seems correct to me (given my understanding of your robot).

Have you double checked all connections? I imagine that the steering motor (motorB) turns either left or right until either the remote controller no longer tells it to, or a touch sensor is pressed creating a physical stop to prevent bad things from happening. Is this correct? That's why I chose to use:

Code:
    // This group is tied together------------------------------
    if (joy1Btn(1) && (SensorValue[S2] == 0))               // |
    {                                                       // |
      motor[motorB] = 70;                                   // |
    }                                                       // |
    else if (joy1Btn(3) && (SensorValue[S4] == 0))          // |
    {                                                       // |
      motor[motorB] = -70;                                  // |
    }                                                       // |
    else                                                    // |
    {                                                       // |
      bFloatDuringInactiveMotorPWM = false;                 // |
      motor[motorB] = 0;                                    // |
    }                                                       // |
    //----------------------------------------------------------


The first condition asks if button 1 is pressed on the joystick AND if the touch sensor in S2 is not pressed. This tells the robot to turn motorB ON at 70 as long as both parts of the above condition are true. For example, the steering is straight so none of the touch sensors on either side are being pressed, I push button 1 and the motor starts spinning until I either let go of button 1 or the touch sensor S2 is pressed (whichever happens first). Once one of these events happens, the condition will be either [TRUE && FALSE], [FALSE && TRUE], or [FALSE && FALSE] which all result in an overall FALSE so that if will then be skipped over.

The second one does the same thing with -70 and touch sensor S4.

The 3rd, which is the default case if all others return FALSE, it will stop motorB by setting it to 0.

Here is a logic table of each case (some not possible):
Code:
| Btn(1) | S2 | Btn(3) | S4 | RESULT |
|--------|----|--------|----|--------|
|   T    | T  |   T    | T  | Not physically possible
|   T    | T  |   T    | F  | motorB = -70
|   T    | T  |   F    | T  | Not physically possible
|   T    | T  |   F    | F  | motorB = 0
|   T    | F  |   T    | T  | motorB = 70
|   T    | F  |   T    | F  | motorB = 70, motorB = -70 (this is a person holding down both joystick buttons while steering is straight)
|   T    | F  |   F    | T  | motorB = 70
|   T    | F  |   F    | F  | motorB = 70
|--------|----|--------|----|
|   F    | T  |   T    | T  | Not physically possible
|   F    | T  |   T    | F  | motorB = -70
|   F    | T  |   F    | T  | Not physically possible
|   F    | T  |   F    | F  | motorB = 0
|   F    | F  |   T    | T  | motorB = 0
|   F    | F  |   T    | F  | motorB = -70
|   F    | F  |   F    | T  | motorB = 0
|   F    | F  |   F    | F  | motorB = 0
|--------|----|--------|----|--------|


If you count them, you will find 3 cases where motorB = 70, 3 cases were motorB = -70, 5 cases where motorB = 0, 4 cases that are not physically possible (both touch sensors pressed at the same time), and 1 case where both buttons are pressed while both touch sensors are not, resulting in the code favoring motorB.

It seems that we covered all cases. Now understand that since button 1 is the first to be checked that this code favors button 1 slightly. If you press both buttons down together, it should act as if button 1 is pressed since it checks that one first. But that is not the cause of your issue. I can't see any problem other than possible hardware.

What do you think?

_________________
Bence Feher

Undergraduate Intern - NREC, Robotics Academy
ROBOTC - Testing/Documentation/Developer

Computer Science, Japanese, East Asian Studies
University of Pittsburgh, Konan University 甲南大学


Mon Jun 27, 2011 11:16 am
Profile
Rookie

Joined: Sat Mar 12, 2011 12:22 pm
Posts: 17
Post Re: Exception Violation with joystick
Hi again

I'm very sorry for such long response time, but we (my family and I) have moved so there's a bit of chaos everywhere.
On top of that, i'm missing one box with my stuff and I can't find my joystick :?
So it may take an even longer while before I can get to testing and finding the issue of this problem

I'll post again when I have some more interesting information (may be weeks)


Wed Jul 13, 2011 12:30 pm
Profile
Rookie

Joined: Sat Mar 12, 2011 12:22 pm
Posts: 17
Post Re: Exception Violation with joystick
Hi again. I have finally found my Joystick in all the mess. I don't know if you remember the problem but it won't work
I have tried running only the steering part code with no luck. If you don't understand the problem take a look at this video I have recorded:
Video


Mon Aug 22, 2011 4:32 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 15 posts ] 

Who is online

Users browsing this forum: No registered users and 8 guests


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

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.