View unanswered posts | View active topics It is currently Wed Aug 27, 2014 8:52 am






Reply to topic  [ 5 posts ] 
Dexter Gyro + JoystickDriver.c problem 
Author Message
Rookie

Joined: Mon Mar 12, 2012 7:13 pm
Posts: 3
Post Dexter Gyro + JoystickDriver.c problem
Hi, I'm fairly new to RobotC, but I'm an experienced programmer (C++, C#, some asm...)

I recently bought the Dexter Industries Gyroscope sensor to realize this segway project:
http://laurensvalk.com/nxt-2_0-only/anyway
It all works great !

But as soon as I add the line
#include "JoystickDriver.c"
The program quits straight away. (I've successfully used the joystick in other projects without the gyro).

If I understand correctly, JoystickDriver.c and segway-driver-lv.h each create a concurrent task. What could be the problem ?
It seems segway-driver-lv.h crashes when calling DIMUconfigGyro(...)

I'm using RobotC 3.05. Here's my faulty program:
Code:
const int your_gyro_sensor = 1;
const tSensors Gyro = S2;
const float your_wheel_diameter = 54;

#include "drivers/DIMU-driver.h"
#include "segway-driver-lv.h"
//#include "JoystickDriver.c"  // !!! Crashes straight away if I uncomment this line !!!

TPCJoystick joystick;

task main()
{
  StartTask(balancing);
  while(starting_balancing_task)
  {}
}


Thanks for the help.


Mon Mar 12, 2012 7:23 pm
Profile
Rookie

Joined: Wed Apr 04, 2007 1:13 pm
Posts: 4
Post Re: Dexter Gyro + JoystickDriver.c problem
Quote:
I recently bought the Dexter Industries Gyroscope sensor to realize this segway project:
http://laurensvalk.com/nxt-2_0-only/anyway
It all works great !


Cool! I recommend to get the latest version of the code from my new site here - http://robotsquare.com/2012/02/13/tutor ... th-robotc/. (Still have to take down that old site, sorry about the trouble).

Quote:
But as soon as I add the line
#include "JoystickDriver.c"
The program quits straight away.


That's interesting. Do you get any error code on the NXT screen as it crashes? Do the motors move at all or does it crash even before that?

Try adding that joystick driver to one of Xanders dIMU sample programs. If this works, then the issue in the Segway program may be the parallel tasks. A known issue is that if multiple tasks try to refer to common.h from Xanders driver suite at the same time, a crash can result.

I don't know the details of "JoystickDriver.c", though. How can it affect the code when you include it even when you make no other references to the code?


Tue Mar 13, 2012 4:41 am
Profile
Rookie

Joined: Mon Mar 12, 2012 7:13 pm
Posts: 3
Post Re: Dexter Gyro + JoystickDriver.c problem
Ok thanks I've updated to the new segway-driver-lv.h just to be sure but it doesn't make a difference for my problem (the differences are small).

Quote:
That's interesting. Do you get any error code on the NXT screen as it crashes? Do the motors move at all or does it crash even before that?
There is no error on the NXT screen, just "Segway-NoAction Running" and very shortly after "Segway-NoAction Done". The motors don't move at all.

Quote:
Try adding that joystick driver to one of Xanders dIMU sample programs.
I suppose you're referring to the official Dexter Gyro tests. This works ! I've added #include "JoystickDriver.c" to DIMU-test1.c and was able to read the Gyro sensor off the NXT screen.

So indeed the problem seems to be the #include "segway-driver-lv.h" with StartTask(balancing); which starts up another task.

Quote:
A known issue is that if multiple tasks try to refer to common.h from Xanders driver suite at the same time, a crash can result.
JoystickDriver.c doesn't include any file

Quote:
I don't know the details of "JoystickDriver.c", though. How can it affect the code when you include it even when you make no other references to the code?
"JoystickDriver.c" starts up its own task automatically by doing that:
Code:
#pragma autoStartTasks        // Automatically start this task when the main user program starts.


So yeah the problem comes from 2 tasks starting at the same time. Maybe I could unify these 2 tasks into 1 ? I would need to understand how both work a bit better though, it's not obvious.

Any ideas ?

Thanks !


Tue Mar 13, 2012 4:31 pm
Profile
Rookie

Joined: Mon Mar 12, 2012 7:13 pm
Posts: 3
Post Re: Dexter Gyro + JoystickDriver.c problem
I've unified both tasks into one into
Code:
task main()
{
  initJoystick();
  initGyro();
  while(starting_balancing_task)
  {
    pollJoystick();
    pollGyro();   
  }
}

And I removed the loop in pollJoystick() that was going through all the messages and it seems to work now. Maybe that was the culprit in the first place.
Balancing and joystick reading are working at the same time. The controls are not very effective though (modifying the speed variable doesn't have a very clear effect), it might be due to 3 things:
- me updating segway-driver-lv.h, it contains new parameters now
- the USB cable tugging at the bot. I can't get the Bluetooth to work again after reinstalling my PC (pairing works fine, but RobotC can't see the brick for some reason)
- the batteries level going down

I suppose I need to investigate a bit more and fix my Bluetooth !


Tue Mar 13, 2012 5:13 pm
Profile
Rookie

Joined: Wed Apr 04, 2007 1:13 pm
Posts: 4
Post Re: Dexter Gyro + JoystickDriver.c problem
Quote:
I suppose you're referring to the official Dexter Gyro tests. This works ! I've added #include "JoystickDriver.c" to DIMU-test1.c and was able to read the Gyro sensor off the NXT screen.
(...)

So yeah the problem comes from 2 tasks starting at the same time. Maybe I could unify these 2 tasks into 1 ? I would need to understand how both work a bit better though, it's not obvious.


Thanks for narrowing down the problem there. An easy way to combine tasks is to read the Joystick within the main control loop of the Segway. If you open up "segway-driver-lv.h", you'll find some sensor and variable declaration code and then a loop for the balance control. Insert the code to poll the joystick just before this snippet:

Code:
    //WAIT THEN REPEAT
     while(time1[T4] < dt*1000){
       wait1Msec(1);}
     ClearTimer(T4);


Presently, each loop cycle lasts 0.01 seconds, 10 ms as defined by this line of code in the configuration lines.
Code:
dt = 0.010;//dt           // Length of each loop


Reading the dIMU twice takes about 4 ms total, which leaves 6 ms for your Joystick. If reading takes longer, that's fine, but then you should modify "dt" accordingly. If reading the joystick takes 11 ms, set dt to (11+4)/1000 = 0.015.

Store your joystick readings in a global variable so you can easily work with them in the main task. With these modifications, using speed and steering should still work as before.

Laurens


Tue Mar 13, 2012 7:53 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 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.