View unanswered posts | View active topics It is currently Sat Sep 26, 2020 8:41 am

Reply to topic  [ 3 posts ] 
Move towards minimum distance detected by sonar 
Author Message

Joined: Mon Nov 12, 2007 10:40 am
Posts: 1
Post Move towards minimum distance detected by sonar
Hi, Newbie to NXT |(5 months) and Robot C (10days). Despite being able to write half decent VBA code I am struggling. Found NXT-G too "foreign" despite doing all tutorials etc, some am trialling (and will buy) Robot C. Have worked thru tutorials and spent a lot of time correcting typo's :(

So 2 questions both based on Brian D's JenToo nesting program (in NXT-G)
I would like to code first part in Robot C, ie rotate through 360 degrees, so have used nSnychMotor and tried to use the encoder to rotate for given number of "ticks", I want to scan with US (sonar) and determine closest detected object, store as variable? and then move towards it.

Secondly I can't find an idiots guide to datalogging, as I'd also like to be able to record US value for every motor encoder increment. So in this case say ca 540 data points and send to PC.

What I have found that for me some coding in Robot C has allowed me to progress with NXT-G and vica versa.

I really like the debugging and variable watch etc rather than having to guess what has gone wrong.

Any help welcomed.

Mon Nov 12, 2007 11:00 am

Joined: Fri Feb 09, 2007 9:21 am
Posts: 616
For Datalogging
Double click on the "Datalog" heading on the ROBOTC left window pane -- the "pane" with all the built in variables displayed. If datalogging is not showing up as a heading, then set the "user level" to "expert" to get the more advanced items displayed.
Open the sample program "NXT Datalog text.c" and study it. It's heavily commented.
If you're still having problems, post again. For faster response, send me an email or PM.

If all you want is a log of 500 points or so, you could also consider simply using a single indexed linear array to hold the values. ANd then watch them using the "Global Variables" debugger window.

Tue Nov 13, 2007 12:14 am

Joined: Fri Feb 09, 2007 9:21 am
Posts: 616
Pseudo-code for above:
for (angle = 0; angle < 360; angle += 30)
move 30 degrees;
wait about 100 msec for sonar to take a reading<BR> if no item found at this angle then continue to next item in loop
if no closest item has been set (i.e. targetAngle < 0) then store angle and distance
if this item is closer than previous closest item then store this angle and disance

if item was found in the above loop
turn to the angle of the item
move straight forward for a littel distance and stop
repeat above again

Tue Nov 13, 2007 12:21 am
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.