go_away

### Author Topic: how to make robot stop and turn 180 degrees  (Read 1307 times)

0 Members and 1 Guest are viewing this topic.

#### greasemonkey94

• Jr. Member
• Posts: 29
##### how to make robot stop and turn 180 degrees
« on: November 21, 2010, 06:39:59 AM »
I am making and obstacle avoiding robot using the sharp IR rangefinder and would like to know how to make the robot stop in one place
and how to make it go in reverse.
Basically if the robot comes up to an object,the rangefinder will scan on both sides and take reading and compare them and decide which way to go.But if it detects objects on all three sides,it should do a 180 and then go straight.

are these right? using the functions in sor_utils.h,

to stop-----> servo_left(35);
servo_right(35);

to turn in reverse direction-----------> servo_left(44);
servo_right(25);

also a much simpler option would be to ask the robot to spin around if it detects an object on both sides and take readings like in
edge detecting code and when it does fnd an opening,it should go straight through,how do i do this??

if i am wrong please tell me the correct values.

here is a copy of the incomplete code

Code: [Select]
`#include "SoR_Utils.h" //includes all the technical stuff//global variablesint sharp_IR_reading=0;int scan_thresh=60;//threshold value of scanning sensor//position of scanner, in units of servo commandint max_scan_angle=56;//maximum position scanner can rotate to (57)//this function decides the direction in which it should turnvoid whichway(void) { //lower (-) goes right //higher (+) goes left //30 far right, 50 straight, 56 far left (until it jams)         servo_scan(56) //look to far left                  int reading1=a2dConvert8bit; //get reading from far left         servo_scan(30); //look to far right         int reading2=a2dConvert8bit; //get reading from far right                    if(reading1<reading2) //object is closer on the right            {             robot_turn_left(); //turn away from object             robot         else if(reading2>reading1) //object is closer on the left            robot_turn_right(); //turn away from object                   else if(reading1=reading2)            //go reverse         else          //spin around              }int main(void) { //LED_on(); initialize(); delay_cycles(42000);//two second wait delay /*********ADD YOUR CODE BELOW THIS LINE **********/ //LED_off();         sharp_IR_reading=a2dConvert8bit(3);         if (sharp_IR_reading<scan_thresh)//object is in danger zone;           {            robot                whichway();//decide which way to go          } delay_cycles(400);//a small delay to prevent crazy oscillations /*********ADD YOUR CODE ABOVE THIS LINE **********/ return 0; }`

and yes the code is based on the code on LMR.

How to fill up the //reverse and the //stop ?

thanks

« Last Edit: November 21, 2010, 09:29:36 AM by greasemonkey94 »