Shop OBEX P1 Docs P2 Docs Learn Events
Mapping a Rectangle using the Activitybot — Parallax Forums

Mapping a Rectangle using the Activitybot

PKTCISMEPKTCISME Posts: 6
edited 2014-05-28 22:09 in General Discussion
Hello. I am trying to have my activitybot use whisker sensors to navigate a rectangle.

The attached files show the method I would like to use to determine the geometry of the rectangle, followed by the pathing.

At this point, I am working on the pathing code. I've been approaching it as follows:

Move forward until the whisker senses an event. Back up until it can turn left 90 degrees without interference. Travel a variable distance forward, called short_distance. Turn left 90 degrees and go forward l_height distance, or until the whisker is triggered again. (The whisker trigger would be ideal in order to reduce error.) After the second whisker event, it should turn right 90 degrees, travel short_distance and turn right 90 degrees. Then travel forward again either l_height or until another whisker event occurs.

Ideally, we want the travel to end on the bottom left corner so as to allow the bot to travel to the reset point and do the path again.
640 x 480 - 52K
640 x 480 - 54K

Comments

  • PKTCISMEPKTCISME Posts: 6
    edited 2014-04-29 13:51
    If anyone has any questions, feel free to ask. I have about 2 weeks until our deadline.
  • TtailspinTtailspin Posts: 1,326
    edited 2014-04-29 14:21
    Can you make your Activitybot move forward until a whisker event, and then stop?, have you done this step?

    Funny, the STOP command seems to always be the first command i try to perfect... :)



    -Tommy
  • PKTCISMEPKTCISME Posts: 6
    edited 2014-04-30 21:28
    I am currently running a while loop which has the bot continuously move forward until an event occurs. Within this loop, there is an if statement which picks up on the whisker sensor input. It then backs up and turns left 90 degrees, goes forward for a set distance, and turns left 90 degrees. From here, the while loop function has the bot travel forward until it impacts again.

    It is basically a modification of the code used here:
    http://learn.parallax.com/activitybot/whisker-wheel-response

    I am thinking of taking out the while loop and just having a chain of commands control the bot instead. I believe I may code it as follows:
    This will be plain english until I get the language down better.

    A counter variable will be set to 0.
    If whisker does not recieve input, move forward.
    If whisker event occurs, counter = counter + 1, back up, turn left 90 degrees, proceed forward a set distance, left turn 90 degrees.

    Ideally, the bot should move forward after this set of functions are complete.
    The second whisker event will occur with the following functions resulting:
    counter = counter - 1
    Turn right 90 degrees, move forward a set distance, turn right 90 degrees.
    From here, the bot should move forward again.
  • PKTCISMEPKTCISME Posts: 6
    edited 2014-04-30 21:34
    I am thinking I may add a total counter in the following manner:
    outside the initial loop:
    if whisker event occurs, total_counter = +1
    this will aid the bot in not getting stuck in the far end corner.
    It should also allow for the bot to return to the beginning of the mapping (seen in the drawing as the bottom right corner)
    This will allow for multiple passes in the same rectangular pattern.

    Our main goal is to map a magnetic field in 3 dimensions.
    We already have code for a spiral and a straight line.
    Eventually, we will add code in which will allow for pauses after a certain distance has been achieved.
    We are making a simple gui in Labview to allow users to determine how many measuring spots they can have in a given space.

    I can see the potential for using a for loop if we consider each set of left and right turns as one full pass.
  • PKTCISMEPKTCISME Posts: 6
    edited 2014-05-07 14:01
    Found how to stop it.
    You can put an if statement with a break.

    If (n == 50) break

    The way I'm going to use it is as follows:
    Set a distance you want to travel and set n equal to that
    http://learn.parallax.com/propeller-c-start-simple/code-repeats
  • PKTCISMEPKTCISME Posts: 6
    edited 2014-05-28 19:32
    Here is the code that allows for the above rectangular travel. The number of top passes can be tailored to each project.

    /*
    This is the main Rectangular code with drive32 turns and straight program file.
    */
    #include "simpletools.h" // Include simple tools
    #include "abdrive.h"
    #include "math.h"


    int main() // Main function
    {
    // DECLARATION OF VARIABLES

    int L_Width_Measured = 600; //Width in millimeters, found from calibration sequence Originally set to 1000 mm
    int L_Height_Measured = 200; //Height in millimeters, found from calibration sequence Originally set to 400 mm
    int t = 2; //Number of top passes Originally set to 2 passes
    int b = t-1; //Number of bottom passes Originally set to 1 passes
    float X_Distance = L_Width_Measured/((2*t)-1); //X_Distance traveled; also known as pass distance Originally set to 200 mm
    float X_Distance_ticks = X_Distance/3.25; //Ticks traveled for X Distance drive function Originally 6.154mm
    float up_and_down = (L_Height_Measured-105.8); //Distance the bot picked up from step (4) in diagram for rectangular pathing
    float up_and_down_ticks = up_and_down/3.25; //Ticks traveled for up and down drive function
    int n;
    int right_turn_pause = 870;
    int left_turn_pause = 870;
    int increment = 50; //pause increments in mm
    float X_Distance_pause_time = (X_Distance_ticks*1000)/(32);
    float up_and_down_pause_time = (up_and_down_ticks*1000)/(32);

    print(" L_Width_Measured = %d mm\n t = %d passes\n b = %d passes\n X_Distance = %d mm\n X_Distance_ticks = %d ticks \n up_and_down = %d mm \n up_and_down_ticks = %d ticks\n Pause/Sensor Intervals = %d \n", L_Width_Measured, t, b, X_Distance, X_Distance_ticks, up_and_down, up_and_down_ticks, increment);




    for(n = 1; n<t; n++) //Repeat t-1 times
    {
    for ( int i = 0; i<up_and_down; i+=increment)//Go forward up_and_down distance with pause every increment i distance
    {
    drive_speed(32, 32);
    pause(((increment/3.25)/20*1000));
    drive_speed(0,0);
    pause(500);
    }

    drive_speed(-32, 32); //90 degrees left turn
    pause(left_turn_pause);
    drive_speed(0,0);
    pause(500);


    for (int i = 0; i<X_Distance; i+=increment) //Go forward X_Distance distance with pause every increment i distance
    {
    drive_speed(32, 32);
    pause(((increment/3.25)/20*1000));
    drive_speed(0,0);
    pause(500);
    }

    drive_speed(-32, 32); //90 degrees left turn
    pause(left_turn_pause);
    drive_speed(0,0);
    pause(500);

    for (int i = 0; i<up_and_down; i+=increment) //Go forward up_and_down distance with pause every increment i distance
    {
    drive_speed(32, 32);
    pause(((increment/3.25)/20*1000));
    drive_speed(0,0);
    pause(500);
    }


    drive_speed(32, -32); //90 degrees right turn
    pause(right_turn_pause);
    drive_speed(0,0);
    pause(500);


    for (int i = 0; i<X_Distance; i+=increment) //Go forward X_Distance distance with pause every increment i distance
    {
    drive_speed(32, 32);
    pause(((increment/3.25)/20*1000));
    drive_speed(0,0);
    pause(500);
    }
    drive_speed(32, -32); //90 degrees right turn
    pause(right_turn_pause);
    drive_speed(0,0);
    pause(500);
    print("this is pass n = %d\n", n);
    }

    // Final Set of Passes


    for(n=n; n<=t; n++) //Final set of passes
    {
    for (int i = 0; i<up_and_down; i+=increment) //Go forward up_and_down distance with pause every increment i distance
    {
    drive_speed(32, 32);
    pause(((increment/3.25)/20*1000));
    drive_speed(0,0);
    pause(500);
    }
    drive_speed(-32, 32); //90 degrees left turn
    pause(left_turn_pause);
    drive_speed(0,0);
    pause(500);

    for (int i = 0; i<X_Distance; i+=increment) //Go forward X_Distance distance with pause every increment i distance
    {
    drive_speed(32, 32);
    pause(((increment/3.25)/20*1000));
    drive_speed(0,0);
    pause(500);
    }

    drive_speed(-32, 32); //90 degrees left turn
    pause(left_turn_pause);
    drive_speed(0,0);
    pause(500);

    for (int i = 0; i<up_and_down; i+=increment) //Go forward up_and_down distance with pause every increment i distance
    {
    drive_speed(32, 32);
    pause(((increment/3.25)/20*1000));
    drive_speed(0,0);
    pause(500);
    }
    print("the final n value is %d.\n", n);
    }
    // n = n + 1;
    // print("n is now bigger than the loop n = %d\n", n);
    }
  • TtailspinTtailspin Posts: 1,326
    edited 2014-05-28 22:09
    PKTCISME, way to go!, working through a challenge like that, it's not easy if you've never done it before, but it's even harder if you never try at all... :)


    I've been out of town for a couple of weeks, and missed your post about you learning how to stop your machine, Turns out to be fairly important yes?.

    I don't write much code using C, maybe you could 'archive' your code and post that up, so that others could learn from your success.


    Congrats again, and keep up the good fun.


    -Tommy
Sign In or Register to comment.