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

Rotaing radar ultrasonic sensor
http://robotc.net/forums/viewtopic.php?f=1&t=5735
Page 1 of 1

Author:  Strma [ Sun Apr 21, 2013 12:11 pm ]
Post subject:  Rotaing radar ultrasonic sensor

Hello everybody
I'm new in programming, using RobotC and I'm trying to navigate my NXT robot around using UltraSonic sensor attached to motor(A). I'd like it to do 180° scans (centerline and 90° to the left and right in 30° increments ( guess that should be sufficient considering width of the ultrasonic "beam") then compare measurements to use the largest one to point my robot toward direction that particular measurement was taken from (motor(A) possition in degrees).
Is it possible (And if it is, please, how?) to "store" those parameters and feed them to drive motors (B&C) making the robot travel in direction without obsticles?
Is there a way to do all that in motion or the robot should stop while scaning?

Author:  NeXT-Generation [ Sun Apr 21, 2013 1:01 pm ]
Post subject:  Re: Rotaing radar ultrasonic sensor

Yes, it's certainly possible. In fact, pretty easy, depending on how you're gonna choose which direction to go in. I imagine you'd start with an array like this:
Code:
ubyte (or int, but ubyte takes up least space) arrayForDistance[#ofscans];


And then have a for loop which moves the US sensor 30* and then takes a US reading, storing it in the equivalent array element.

Now, depending on what you want for navigation, you could just go with the greatest distance, or something else. You could make a function for turning, and pass in which way and how far to turn. It'd be best to stop and scan, so that you don't run into anything while scanning. Maybe scan again when you see something get close.

If you need anything explained, just say so. I certainly had no idea what arrays or elements or for loops where when I first started, since RobotC was the first programming language I learned.

Author:  Strma [ Sun Apr 21, 2013 3:30 pm ]
Post subject:  Re: Rotaing radar ultrasonic sensor

Thank you NeXT-Generation for finding time to answer my absolute beginner question.
As you already guess I got no clue about arrays and as far as looping, I just start to scratch the subject :(
What I had in mind was robot finding an area where the obsticle is farther and drive to it untill reaching some safe distance...then scan to find another "free"way and travel there.
I looked everywhere to find something to help me understand "mechanics" behind such scenario but without success.
I'd be more than grateful if you would share some of your knowledge and help me crack this problem with some example and step-by step guidance.

Author:  NeXT-Generation [ Sun Apr 21, 2013 4:52 pm ]
Post subject:  Re: Rotaing radar ultrasonic sensor

Basic working of a for loop and arrays:

Basic for loop:
Code:
for(int x = 0; x < 10; x++)//creates variable "x" and increases it by one each time the loop runs, until it's run 10 times, or, in other words, until x = 10.
{
   nxtDisplayCenteredBigTextLine(2, "%d", x);//Displays value of variable "x"
   wait1Msec(500);//Waits for 0.5 seconds
}


Basics of array usage:
Code:
int exampleArray[10];// creates an array of type "integer" and names it "exampleArray".  This array has 10 elements in it, signified by the square-bracketed 10.

//Array "elements" are the individual parts of the array, and can be accesed and changed like this.

exampleArray[0] = 1;//Set element 0 to a value of 1.  The count starts at 0, so this array has the elements 0-9
nxtDisplayCenteredBigTextLine(2, "%d", exampleArray[0]);//Displays the value of array element 0

//So, to summarise, an array is basically an easy and compact way to deal with a bunch of similar variables.  I use "exampleArray[10]" instead of
//ExampleVar1, ExampleVar2, ExampleVar3, etc.


So, that's the raw basics. A quick Google search will give more detailed info.

And here's a for loop with arrays!
Code:
int USReadings[6];

for(x = 0; x < 6; x++)
{
   USReadings[x] = SensorValue(USSensor);
}


So, that's basically what you need for your project. At least for starters. Still need motor movements, path deciding and the like.

Author:  NeXT-Generation [ Sun Apr 21, 2013 4:54 pm ]
Post subject:  Re: Rotaing radar ultrasonic sensor

Oh and btw, you can usually just use integers for your number variables. The only real need to use as small as bytes is if you have a huuuge program or are transmitting messages via BT, RS485, or other means. Just a force of habit with me to use the smallest I'd need.

Author:  Strma [ Mon Apr 22, 2013 5:42 am ]
Post subject:  Re: Rotaing radar ultrasonic sensor

Thank you NeXT-Generation fo your efforts to enlighten me :)

Author:  Coder A [ Mon Apr 22, 2013 4:52 pm ]
Post subject:  Re: Rotaing radar ultrasonic sensor

Yeah, I almost never use int. Short is the same thing on most platforms.

Author:  MHTS [ Thu May 02, 2013 2:54 am ]
Post subject:  Re: Rotaing radar ultrasonic sensor

Strma wrote:
Hello everybody
I'm new in programming, using RobotC and I'm trying to navigate my NXT robot around using UltraSonic sensor attached to motor(A). I'd like it to do 180° scans (centerline and 90° to the left and right in 30° increments ( guess that should be sufficient considering width of the ultrasonic "beam") then compare measurements to use the largest one to point my robot toward direction that particular measurement was taken from (motor(A) possition in degrees).
Is it possible (And if it is, please, how?) to "store" those parameters and feed them to drive motors (B&C) making the robot travel in direction without obsticles?
Is there a way to do all that in motion or the robot should stop while scaning?

This will not help you regarding basic programming but I do have a robotics library that incidentally contains a radar module that does exactly what you want. It's developed as an object in the library. If you have some concept on object oriented programming, you will feel at home using the library. You can also look at the source code to learn how it uses array to implement the functions. The radar object consists of an ultrasonic sensor and a motor. By default, you can register up to 4 sampling positions but you can override it by defining higher number for the MAX_SAMPLE_POINTS define. After the radar object is initialized, you can make several calls to RadarAddSample to register several degree positions you want the radar to scan. After that you can call RadarSetState with true to start the scanning or false to stop the scanning. At any time, you can call RadarGetData with a given degree angle to get the reading for that angle. Here is the source code to the radar module:
http://proj.titanrobotics.net/hg/Ftc/20 ... ib/radar.h
If you are interested in using the library module, let me know and I can walk you through how to use the library.

Author:  TORQUE [ Thu May 02, 2013 8:24 am ]
Post subject:  Re: Rotaing radar ultrasonic sensor

NeXT-Generation wrote:
Oh and btw, you can usually just use integers for your number variables. The only real need to use as small as bytes is if you have a huuuge program or are transmitting messages via BT, RS485, or other means. Just a force of habit with me to use the smallest I'd need.


Hi pls i would need u to explain more about how to transmit message via BT or let me say intruction. for example how can u specify to the robot the amount of distance to travel next while its running? thank you in anticipation guys

Author:  NeXT-Generation [ Thu May 02, 2013 9:20 am ]
Post subject:  Re: Rotaing radar ultrasonic sensor

TORQUE wrote:
NeXT-Generation wrote:
Oh and btw, you can usually just use integers for your number variables. The only real need to use as small as bytes is if you have a huuuge program or are transmitting messages via BT, RS485, or other means. Just a force of habit with me to use the smallest I'd need.


Hi pls i would need u to explain more about how to transmit message via BT or let me say intruction. for example how can u specify to the robot the amount of distance to travel next while its running? thank you in anticipation guys
Don't hijack threads. Make a new one.

Author:  Strma [ Fri May 03, 2013 2:54 am ]
Post subject:  Re: Rotaing radar ultrasonic sensor

Quote:
This will not help you regarding basic programming but I do have a robotics library that incidentally contains a radar module that does exactly what you want. It's developed as an object in the library. If you have some concept on object oriented programming, you will feel at home using the library. You can also look at the source code to learn how it uses array to implement the functions. The radar object consists of an ultrasonic sensor and a motor. By default, you can register up to 4 sampling positions but you can override it by defining higher number for the MAX_SAMPLE_POINTS define. After the radar object is initialized, you can make several calls to RadarAddSample to register several degree positions you want the radar to scan. After that you can call RadarSetState with true to start the scanning or false to stop the scanning. At any time, you can call RadarGetData with a given degree angle to get the reading for that angle. Here is the source code to the radar module:
http://proj.titanrobotics.net/hg/Ftc/20 ... ib/radar.h
If you are interested in using the library module, let me know and I can walk you through how to use the library.



Thank you very much MHTS

I'm not very skillful in programming but I'll certainly take a look into your code and then come back with a lot of questions :-)

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