go away spammer

Author Topic: robot algorithm not working right  (Read 2500 times)

0 Members and 1 Guest are viewing this topic.

Offline pomprockerTopic starter

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
    • Nerdcore - Programming, Electronics, Mechanics
robot algorithm not working right
« on: July 17, 2008, 07:51:28 PM »
I can't seem to wrap my head around this. When my robot sees something on the right I want it to go left. When it sees something on the left, I want it to go right. When something jumps in front of it, it goes backwards. Don't worry about the values. I just need to know if this is the correct control structure:
Code: [Select]

while(1) {
     scan();
     ping();

     //Object Avoider
       
     if (PingVal > 8) {
          if (sharp_IR_reading > scan_thresh) {
        if (scan_angle > 410)
     robot_turn_right();
                else if (scan_angle < 390)
     robot_turn_left();
                 else
                      robot_go_back();
          }  // end if
          //object is centered
          else
                robot_go_straight();
     }  // end if
     else {
          while (PingVal < 16) {
               robot_go_back();
ping();
          }
     }  // end else
     delay_cycles(3200);//a small delay to prevent crazy oscillations -> 400 * 8
}  // end while


« Last Edit: July 18, 2008, 11:25:14 AM by pomprocker »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: robot algorithm not working right
« Reply #1 on: July 20, 2008, 04:44:03 PM »
I'm not entirely clear on your setup.

You have a sharp IR as your only sensor, right? I see you included scan_angle, but you have no code to move the sensor . . .

I'd do something like:
Code: [Select]
IR=get_sensor_value();

//control robot
if (IR > thresh && scan_angle > 410)//sees something on left
   turn_right();
else if (IR > thresh && scan_angle < 390)//sees something on right
   turn_left();
else if (IR > thresh)//sees something in front
   go reverse();//it will oscillate at the threshold here

//control scanner
if (IR < thresh)//doesn't see anything
   rotate_left();
else //sees something
   rotate_right();

Its a little bit more complicated than this, and you'll have oscillation issues for sure so you'll have to play around with it.
   

Offline pomprockerTopic starter

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
    • Nerdcore - Programming, Electronics, Mechanics
Re: robot algorithm not working right
« Reply #2 on: July 20, 2008, 06:47:55 PM »
I have a parallax ping sonar now too  ;D its for when something jumps in front of the robot and the scanner misses it. then it backs up a bit and rescans the area.

 


Get Your Ad Here

data_list