Shop OBEX P1 Docs P2 Docs Learn Events
ActivityBot robot kit roaming with ping and compass? — Parallax Forums

ActivityBot robot kit roaming with ping and compass?

azad.omerazad.omer Posts: 12
edited 2015-05-26 15:51 in Robotics
Dear all,

After posting a thread about if someone have ready project on roaming with ping and compass, you guys asked me to try it myself.
Well, I tried and spend many time on it.
Now, I'm in situation of I don't know what to do and the below codes have problems, logically I think it's okay but when I runt it on the robot it acts different.
Tomorrow is the final day of presenting this project, please please if anyone have already finished this project provide me the codes.

Here is what I tried:
#include "simpletools.h"                      
#include "servo.h"
#include "ping.h"                          
#include "abdrive.h"

int main(){ //MAIN
  int servo = 17;
  int ping = 12;
  int angles[] = {0, 450, 900, 1350, 1800};
  
  while(1)
  { //Start of main While
    int dis = ping_cm(ping);
    
    if(dis < 15)
    { //Start  of IF(#1)
      drive_speed(0, 0);
      //stop the wheels, look around
      
      for(int i=0; i<5; i++)
      { //Start of For-Loop
        servo_setramp(servo, 30);
        servo_angle(servo, angles[i]);
        pause(1000);
        dis = ping_cm(ping);
        
        if(dis < 20)
        { //Start of IF(#2)
          print("Distance= %d\n", dis);
          freqout(2, 1000, 1047);
        }//End of IF(#2)
        
        else 
        { // Start ELSE(#1)
          print("Distance OK %d\n", dis);
          freqout(2, 1000, 2093);
        }//End of ELSE(#1)
        
      }//End of FOR-LOOP
      
    }//End of IF(#1)
    
    else
    { //Start of ELSE(#2)
      print("Distance OK %d\n", dis);     
      drive_speed(60, 60);
    }//end of ELSE(#2)
                                         
  }//End of WHILE    
       
}//END OF MAIN

Comments

  • GenetixGenetix Posts: 1,754
    edited 2015-05-26 10:12
    Hello Azad,

    Please use code blocks "[ code ]" and '[ /code ]" around your code so the formatting is preserved. (no spaces or quotes)
    Notice that you have 2 "hanging" braces in the middle of your program and the 2 ending braces are missing.
    int main() 
       {     // Start of MAIN
       int servo = 17;
       int ping = 12;
       int angles[] = {0, 450, 900, 1350, 1800};
    
       while(1)
          {     // Start of WHILE
    
          int dis = ping_cm(ping);
    
          if(dis < 15)
             {     // Start of IF (#1)
             drive_speed(0,0);
             //stop the wheels
             //look around
    
             for(int i=0; i<5; i++)
                {     // Start of FOR
                servo_setramp(servo, 30);
                servo_angle(servo, angles[i]);
                pause(1000);
                dis = ping_cm(ping);
    
                if(dis < 20)
                   {     // Start of IF (#2)
                   print("Distance= %d\n", dis); 
                   freqout(2, 1000, 1047); //pin, duration, frequency 
                   }     // End of IF (#2)
    
                else
                   {     // Start of ELSE (#1)
                   print("Distance Okey----- %d\n", dis); 
                   freqout(2, 1000, 2093); //pin, duration, frequency 
                   }     // End of ELSE (#1)
     
                }                         // What does this go to?
                }                         // What does this also go to?
    
                else
                   {     / Start of ELSE (#2)
                   print("Distance Okey= %d\n", dis); 
                   drive_speed(-60, -60);
                   }     // End of ELSE (#2)
    
                }//while                          [***** Must be the end of FOR]
             }                               // Must be the end of IF (#1)
          // End of WHILE should be here!
       // End of MAIN should be here!
    
  • azad.omerazad.omer Posts: 12
    edited 2015-05-26 10:58
    Genetix wrote: »
    Hello Azad,

    Please use code blocks "[ code ]" and '[ /code ]" around your code so the formatting is preserved. (no spaces or quotes)
    Notice that you have 2 "hanging" braces in the middle of your program and the 2 ending braces are missing.

    Thanks Genetix, I've updated my post and added comments for each brackets.
    I'm sure that my code is not correct about roaming, if you can help me I will be appreciate it.
  • GenetixGenetix Posts: 1,754
    edited 2015-05-26 13:33
    Azad,

    It would have been better had you continued with your original post or provided the link for it.
    http://forums.parallax.com/showthread.php/160854-ActivityBot-robot-kit-with-ping-and-compass-project

    Looking at that post you never did say what you wanted your bot to do.
    The way your code it written it will scan in 45 degree increments if the initial distance is less than 15 cm or reverse direction otherwise.
    If your bot does a scan then it beeps high if the distance is greater than 20, otherwise it beeps low.
    It just keeps repeating the same action.

    Is that what you intended it to do?
  • azad.omerazad.omer Posts: 12
    edited 2015-05-26 13:43
    Genetix wrote: »
    Azad,

    It would have been better had you continued with your original post or provided the link for it.
    http://forums.parallax.com/showthread.php/160854-ActivityBot-robot-kit-with-ping-and-compass-project
    ......

    Is that what you intended it to do?

    No, actually I want my bot to go around the room, but when it faces an object it stops.
    and look around to see if there is a way to go, I mean object avoidance.
    That's what I want to do.
    By the way, how to turn my bot using angle? for example 45 degree using drive_speed function?
  • GenetixGenetix Posts: 1,754
    edited 2015-05-26 14:15
    Here is code for avoiding objects using a Ping.
    http://learn.parallax.com/activitybot/roaming-ultrasound
    Notice the negative signs in the Drive_Speed commands, which will make that wheel turn in reverse.

    This Speed Control Example is for a 45 degree Right Turn.
    http://learn.parallax.com/activitybot/set-certain-speeds
    Notice in the middle Drive_Speed how the Left wheel is commanded to turn while the Right wheel stays still.
  • azad.omerazad.omer Posts: 12
    edited 2015-05-26 14:41
    Genetix wrote: »
    Here is code for avoiding objects using a Ping.
    http://learn.parallax.com/activitybot/roaming-ultrasound
    Notice the negative signs in the Drive_Speed commands, which will make that wheel turn in reverse.

    This Speed Control Example is for a 45 degree Right Turn.
    http://learn.parallax.com/activitybot/set-certain-speeds
    Notice in the middle Drive_Speed how the Left wheel is commanded to turn while the Right wheel stays still.

    Thanks, I tried the first link several times, also the other examples but again it's not complete and it acts weird.
    I hoped that you have the same project.
  • GenetixGenetix Posts: 1,754
    edited 2015-05-26 15:51
    Azad,

    What do you want your bot to do?
    You were asked thus question a month ago and you never answered it so there is not much we can do for you now.

    We have pointed you to code to do what you ask about but that code will not do exactly what you want. You need to modify it to do what you want.
    What is the code doing that it shouldn't or what is it not doing that it should?

    Explain what you can't get the code to do or what it's doing that it should not be doing and we can help you resolve it.
    Check your batteries though because weak batteries will make even good code act strange.

    Add this line between MAIN and WHILE
    freqout(2, 2000, 3000); // pin, duration, frequency (Reset Indicator - 3 kHz for 2 seconds)
    If you keep hearing this long beep then your batteries are weak and need to be replaced.
Sign In or Register to comment.