ROBOTC.net forumshttp://robotc.net/forums/ Rotaing radar ultrasonic sensorhttp://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 everybodyI'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-9nxtDisplayCenteredBigTextLine(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!

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 everybodyI'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?

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