ROBOTC.net forums
http://www.robotc.net/forums/

NXT Radar display
http://www.robotc.net/forums/viewtopic.php?f=1&t=199
Page 1 of 1

Author:  NXTUser [ Mon Jun 11, 2007 3:28 am ]
Post subject:  NXT Radar display

Hi all,

I`m fairly new to the NXT environment, only about 1 month now, I started with the NXT-G but quickly switched to the ROBOTC !! Much easier to use, I bough the software and enjoy it very much. Here is a piece of code that I modified, the spiral drawing app. that converts the display into a typcal RADAR display.
I still have a lot to learn :lol: :lol: :lol:
I attached the SONAR sensor with GREAT difficulty to a motor port, (getting horisontal movement to vertical is not easy), it sweeps from right to left and back, displaying a trace on the LCD as a sweeping line. As soon as the sonar pics up a target it blips it on the display and controls the other motor wheels.
OH I forgot, the sonar sensor quickly goes out of sync, so to sync it I added the touch sensor so that every left to right sweep syncronize the netx sweep, so that the cable doesn`t get snapped off etc. :lol:
Its just a test, and needs MUCH !!!! improvement, but for those out there like myself examples help allot.
1- Here is one for the development team, how about a line erase function. All good and well you can draw it, but you cannot erase it easilly !!
2- The sonar sensor is a pain (at least the one I have), I don`t know if its the software or the device, but it seems to be very erratic and inacurate. It mostly displays a value of 24, and when in RAW mode 255 is the default, and then also reverts to 24. The distance is also VERY inaccurate ? Anyone else has this problem ? If not I suspect the device is a bit faulty.
(Comments welcome)
Here is the code, simply copy and paste

Code:
//*!!Sensor,    S1,          touchSensor, sensorTouch,      ,                    !!*//
//*!!Sensor,    S2,          sonarSensor, sensorSONAR,      ,                    !!*//
//*!!Motor,  motorA,               motorA, tmotorNxtEncoderClosedLoop,           !!*//
//*!!Motor,  motorB,           rightMotor, tmotorNxtEncoderClosedLoop,           !!*//
//*!!Motor,  motorC,            leftMotor, tmotorNxtEncoderClosedLoop,           !!*//
//*!!                                                                            !!*//
//*!!Start automatically generated configuration code.                           !!*//
const tSensors touchSensor          = (tSensors) S1;   //sensorTouch        //*!!!!*//
const tSensors sonarSensor          = (tSensors) S2;   //sensorSONAR        //*!!!!*//
const tMotor   motorA               = (tMotor) motorA; //tmotorNxtEncoderClosedLoop //*!!!!*//
const tMotor   rightMotor           = (tMotor) motorB; //tmotorNxtEncoderClosedLoop //*!!!!*//
const tMotor   leftMotor            = (tMotor) motorC; //tmotorNxtEncoderClosedLoop //*!!!!*//
//*!!CLICK to edit 'wizard' created sensor & motor configuration.                !!*//

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                              Draws a Spiral on the NXT LCD
//
// Contributed by Count Olaf.
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma platform(NXT)
#define LCD_CENTER_X 50
#define LCD_CENTER_Y 32
#define MAX_ANGLE 270
#define MIN_ANGLE 90
#define MAX_RADIUS 32
#define SONAR_SCALE 2
#define STEP_ANGLE 15
#define SONAR_RANGE 30

void drawCircle()
{
   float nAngle;
int X, Y;
float nRadius;
   nRadius = MAX_RADIUS;
   nAngle = 0;
   while(nRadius > 0)
   {
      X = sinDegrees(nAngle) * nRadius + LCD_CENTER_X;
      Y = cosDegrees(nAngle) * nRadius + LCD_CENTER_Y;
      nxtSetPixel(X, Y); // Center of screen is (50, 32)

      //nRadius -=.02;
      ++nAngle;
      if(nAngle >= 360){
         nRadius-=10;
         nAngle = 0;
      }
   }
}
//************************************************
void drawLine()
{
   float nAngle;
   int X, Y, sonar;
   unsigned char x,y;
   float nRadius;
   nRadius = 0;
   nAngle = 90;
   //sweeping to right
   nMotorPIDSpeedCtrl[motorA] = mtrSpeedReg;
   motor[motorA] = 15;
   PlaySound(soundBlip);
   while(nAngle < MAX_ANGLE)                  // one complete circle
   {
      X = sinDegrees(nAngle) * nRadius + LCD_CENTER_X;  //get x coordinate
      Y = cosDegrees(nAngle) * nRadius + LCD_CENTER_Y;   //get y coordinate
      nxtSetPixel(X,Y);                     //draw pixel on lcd
      ++nRadius;
      if(nRadius >= MAX_RADIUS){
         sonar = SensorRaw[sonarSensor];
         sonar = sonar/SONAR_SCALE;
         wait1Msec(100);
         for(x=0;x<nRadius;x++){
            X = sinDegrees(nAngle) * x + LCD_CENTER_X;  //get x coordinate
            Y = cosDegrees(nAngle) * x + LCD_CENTER_Y;   //get y coordinate
            if(x==sonar){         //somthing ahead
               PlaySound(soundShortBlip);
               if(sonar <= SONAR_RANGE){
                  motor[rightMotor] = 0;
                  motor[leftMotor] = -30;
                  motor[motorA] = 0;
                  wait1Msec(200);
               }
            }
               motor[motorA] = 15;
            motor[rightMotor] = 50;
            motor[leftMotor] = 50;
            if(x!=12 && x!=22 && x!=32 && x !=sonar) //do not erase circles already on LCD, or target blipped
               nxtClearPixel(X,Y);                     //clear pixel already on lcd
         }
         nAngle += STEP_ANGLE;
         nRadius = 0;
      }
   }
//************************************************
   nMotorPIDSpeedCtrl[motorA] = mtrSpeedReg;
   motor[motorA] = -15;
   PlaySound(soundBlip);
   while(nAngle >= MIN_ANGLE)                  // one complete circle
   {
      if(SensorValue[touchSensor] == 1)
      motor[motorA] = 0;
      X = sinDegrees(nAngle) * nRadius + LCD_CENTER_X;  //get x coordinate
      Y = cosDegrees(nAngle) * nRadius + LCD_CENTER_Y;   //get y coordinate
      nxtSetPixel(X,Y);                     //draw pixel on lcd
      ++nRadius;
      if(nRadius >= MAX_RADIUS){
         sonar = SensorRaw[sonarSensor];
         sonar = sonar/SONAR_SCALE;
            wait1Msec(100);
         for(x=0;x<nRadius;x++){
            X = sinDegrees(nAngle) * x + LCD_CENTER_X;  //get x coordinate
            Y = cosDegrees(nAngle) * x + LCD_CENTER_Y;   //get y coordinate
            if(x==sonar){
               PlaySound(soundShortBlip);
               if(sonar <= SONAR_RANGE){
                  motor[rightMotor] = -30;
                  motor[leftMotor] = 0;
                  motor[motorA] = 0;
                  wait1Msec(200);
               }
            }
            motor[motorA] = -15;
            motor[rightMotor] = 50;
            motor[leftMotor] = 50;
            if(x!=12 && x!=22 && x!=32 && x !=sonar) //do not erase circles already on LCD, or target blipped
               nxtClearPixel(X,Y);                        //clear pixel already on lcd
         }
         nAngle -= STEP_ANGLE;
         nRadius = 0;
      }
   }
}

task main()
{
   eraseDisplay();
   drawCircle();
   motor[motorA] = -15;
      while(SensorValue[touchSensor]==0);
      motor[motorA] = 0;
   while (true)
   {

      motor[rightMotor] = 50;
      motor[leftMotor] = 50;
      drawLine();

      //drawCircle();

   }
}
[/code]

Author:  amormachine [ Mon Jul 09, 2007 6:53 pm ]
Post subject:  Radar Whoes ...

I have had the same problem with a radar display! I have no idea what the problem is ... But, as you mentioned, the radar values simply don't seem right. I've noticed that when I point the sonar sensor to something that is really far away, it correctly returns about 255, but then I show it something closer ... at that point, even if I show it something that is extremely far away again, it doesnt seem to return 255 ever again. Anyone have any ideas?

Author:  kbirk [ Sat Jul 14, 2007 3:28 pm ]
Post subject:  Sonar problem

I nearly have the same problem. My sonar shows the right value, but it is very slow to update the value, and sometimes it almost freeze in the same distance/value.
Any one got a fix..?

Author:  JamesD [ Mon Jul 16, 2007 7:55 am ]
Post subject: 

This thread may help you.
http://www.robotc.net/forums/viewtopic.php?t=153

It includes info like:
Quote:
One issue you might be having is that SensorValue(sonar) can exhibit a behaviour where the lowest value "sticks" and doesn't change until a lower value is read and "sticks" again. This reduces the likelihood of accidental misreads (which the sonar can easily do) mucking up your program.

If you want the reading to be more dynamic use SensorRaw(sonar) it wont stick

Author:  thpropst [ Thu Feb 21, 2008 6:00 am ]
Post subject: 

hello,

for me stopping the motor every 5° and waiting about 10ms before reading the US sensor helped a lot.

best regards, thomers.

Author:  Dick Swan [ Wed Feb 27, 2008 10:38 am ]
Post subject: 

THe sonar sensor only polls something like every 50 milliseconds. So if you want to stop briefly to get a reading then 10 milliseconds is too short!

I suppose if you are sweeping back-and-forth very fast you will get erroneous readings if th angle at start of echo pulse transmission is quite different from the angle when the pulse returns and is received. The distance may be accurate but the angle that you get is "wrong".

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/