View unanswered posts | View active topics It is currently Wed Oct 01, 2014 8:26 pm






Reply to topic  [ 5 posts ] 
NXT Overhead using different sensor types 
Author Message
Rookie

Joined: Wed May 28, 2008 11:27 pm
Posts: 1
Post NXT Overhead using different sensor types
I recently ordered and received the compass sensor (Thanks JB! :) )
So as we all know, running the sensor using the regular ultrasonic driver returns 0-179 and loading the compass driver opens up so much more.
However, loading the compass driver has got to increase the overhead on the NXT.
My quick 'n dirty program --


Code:
int motor_speed                                 = 50;
int direction;
int compass_direction;
int drive_time = 600;
int relative_direction;

task display()
{
   while (true)
   {
      nxtDisplayTextLine(1,"Compass:%d",compass_direction);
      nxtDisplayTextLine(2,"Direction:%d",direction);
      nxtDisplayTextLine(3,"relative:%d",relative_direction);
      nxtDisplayTextLine(5,"Time:%d",time1(T1));
   }
}


void get_relative_direction()
{
   compass_direction = (SensorValue(S2) * 2);
   if (direction < 180)
   {
      if ((compass_direction >=0) && (compass_direction <= (direction + 180)))
      {
          relative_direction = compass_direction - direction;
       }
       else
       {
          relative_direction = ((compass_direction - 360) - direction);
       }
   }
   else if (direction >= 180)
   {
      if ((compass_direction <=359) && (compass_direction >= (direction - 180)))
      {
          relative_direction = compass_direction - direction;
       }
       else
       {
          relative_direction = ((compass_direction + 360) - direction);
       }
   }
}


void drive()
{
   get_relative_direction();
   if (relative_direction < -6)
  {
      motor[motorA] = motor_speed;
      motor[motorB] = (motor_speed /4);
      motor[motorC] = -motor_speed;
  }
  else if (relative_direction > 6)
  {
      motor[motorA] = -motor_speed;
      motor[motorB] = (motor_speed /4);
      motor[motorC] = motor_speed;
  }
  else
  {
      motor[motorA] = motor_speed;
      motor[motorB] = -motor_speed;
      motor[motorC] = motor_speed;
  }
}



task main()
{

   SensorType[S2] = sensorSONAR;
   StartTask (display);

   while (true)
   {
      PlaySound(soundBlip);
      ClearTimer(T1);
      direction = 0;
      while (time10(T1) < drive_time)
      {
         drive();
      }

...

just uses the compass readings as ultrasonic and does it's own manual 'relative heading' thing.
So here's the question--will doing the code above regarding the relative heading decrease the overhead on the NXT compared to using the compass sensor drivers doign the same thing?
Just wondering.
By the way, RobotC--fantastic!
Keep up the great work!
Dave K


Mon Jun 02, 2008 12:29 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post 
Hi Dave

The real purpose for using the compass sensor in sonar mode is to let beginners be able to plug it in and use it without to much confusion and make it simple. To use the sensor to its fullest capabilities, I highly encourage people to us the I2c protocol to communicate with the sensor. I will admit, I2C is not something a beginner should use and can be hard on the brain, but it is worth it in the end.

As for slowing down the NXT, I wouldn't worry about it B-). The execution speeds are extremely high compared to NXC and NXG. Also, the driver code is not to much longer than what you have written. There should not be much to worry about. The only thing that I suggest when running many I2C sensors is to try and have them on different ports, that way they don't have to wait for each other to communicate to the NXT, then you might notice slowdown of your program B-)

FordPrefect has posted his code to run the HiTechnic Sensor Here
viewtopic.php?t=463

Glad to hear your enjoying RobotC, and Good luck
Scott B-)

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Last edited by starwarslegokid on Mon Jun 02, 2008 4:48 pm, edited 1 time in total.



Mon Jun 02, 2008 3:06 pm
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
starwarslegokid wrote:
FordPerfect has posted his code to run the HiTechnic Sensor

Ford P-r-e-fect ! :wink:

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Mon Jun 02, 2008 4:01 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post 
lol sorry, I had a dyslexic moment, I fixed it :-)
Thanks for posting your code

Scott B-)

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Mon Jun 02, 2008 4:49 pm
Profile WWW
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post 
Version 1.35 and above has integrated device drivers for all/most of the HiTechnic sensors. There's examples of their use in the samples folder.

ROBOTC is unlike the other alternative programming environments in that the I2C device drivers operate in the background continuously polling the sensors. AFAIK, all the other solutions do "inline" I2C messaging reads to obtain the sensor values -- which takes five milliseconds or more during which time user programs are stalled waiting for the read to complete.

The integrated device drivers make it easier to program with ROBOTC.

Another unique feature of ROBOTC is the built-in measurement statistics on percentage of time spent in background tasks and in user program execution. These are two of the variables that are displayed in the "System Parameters" debugger window. They are also built-in intrinsic variables that you can read within your program. So, if you want to know the overhead of the device drivers, simply add / subtract I2C devices and look at the changes in background time. Last time i looked, with I2C devices on all four sensor ports, it was 18%.


Wed Jun 04, 2008 4:30 am
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.