Shop OBEX P1 Docs P2 Docs Learn Events
Seeking source code for ActivityBot with ping & sweep (570-28015) in Propeller — Parallax Forums

Seeking source code for ActivityBot with ping & sweep (570-28015) in Propeller

BenthePIBenthePI Posts: 8
edited 2015-03-18 08:22 in Propeller 1
Hello everyone,

I'm new to robotics and helping my 8 yo daughter, Kennedy, follow her passion for robots. She's at the age where she can open files and download them to the ActivityBot, however writing code is well above her skill set.

I have found links to the code in stamp, but need it for the PropellerC and ActivityBot. Sorry if the topic was covered and posted, but searched for about 1/2 hour before resorting to posting.

Thank you,

-Ben (Kennedy's Dad)

Comments

  • Hal AlbachHal Albach Posts: 747
    edited 2015-03-16 12:55
    Welcome to the forums!

    Have you seen this page?

    http://learn.parallax.com/activitybot


    Hal
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2015-03-16 12:58
    I don't know about the Ping sweep functionality, but in case you haven't explored the Parallax Learn site yet, all the current tutorials for the ActivityBot may be found here:

    http://learn.parallax.com/activitybot

    Activities specific to the Ping and ActivityBot are here:

    http://learn.parallax.com/activitybot/navigate-ultrasound

    Again, not sure about the sweep aspect, but that's not really necessary to experiment with the ActivityBot, Propeller C, and the Ping. In fact, for her age level, the extra code the BS2 sweep function entails could be confusing.
  • Courtney JacobsCourtney Jacobs Posts: 903
    edited 2015-03-16 13:11
    BenthePI,

    This is a working copy only at the moment, but here is some code produced by Andy Lindsay recently for a tech support customer:
    /*
      Roam with Ping on Servo Turret.c
    
      Turn away from objects detected by sweeping Ping))) on turret servo.
    
      Connect Ping))) to P17 and turret servo to P16.
    */
    
    #include "simpletools.h"                      // Library includes
    #include "abdrive.h"
    #include "ping.h"
    #include "servo.h"
    
    int main()                                    // Main function
    {
      drive_setRampStep(10);                      // Set step size
      drive_speed(128, 128);                      // Initial speed
    
      int angle = 0, distance = 0, sweep = 1;     // Variables
    
      while(1)                                    // Main loop
      {
        if(angle >= 1800)                         // Sweep multiplier
          sweep = -1;
        else if(angle <= 0)
          sweep = 1;
       
        servo_angle(16, angle += (sweep *180));   // Set angle
        pause(50);                                // Let servo get there
    
        distance = ping_cm(17);                   // Check distance
    
        if(distance < 15)                         // Oops, too close
        {
          while(distance < 25)                    // While too close
          {
            drive_rampStep(-128, -128);           // Back up
            distance = ping_cm(17);               // ...and re-check
          }
        }
        else if(distance < 35)                    // If proximate (< 35 cm)
        {
          if(angle > 900)                         // If kinda in front of on right
          {
            while(distance < 35)                  // Freeze turret, turn until
            {                                     // opening
              drive_rampStep(128, 0);             // ...turn right
              distance = ping_cm(17);             // Check distance
            }
          }
          else                                    // If kinda in front of on left
          {
            while(distance < 35)                  // Freeze turret, turn until
            {                                     // opening
              drive_rampStep(0, 128);             // ...turn left
              distance = ping_cm(17);             // Check distance
            }
          }
        }
        else                                      // If not too close
        {
          drive_rampStep(128, 128);               // ... go forward
        }
      }
    }
    

    If you have any issues with it please reply and be as specific with describing your errors as possible. All libraries referenced for this project are available with the Learn folder/SimpleIDE.

    I concur with Gordon and Hal in that you should definitely spend the time to go through the Propeller C and ActivityBot tutorials, if you haven't already. 8 years old is a great age to start learning basic programming skills and concepts.
  • BenthePIBenthePI Posts: 8
    edited 2015-03-16 13:49
    Thank you Hal & Gordon, I'm actually well versed in the learn sites and tutorials and have used them to build all the projects up to the "follow with light" in order. We've got everything built and working up to that point.

    @ Courtney, after reading that actually looks like what I'm after. It looks like the servo is using Pin 16 and the ping to 17. I assume both are 5 volt on the VIn.

    Is there any other information needed like do the resistors to P14 & P15 remain in place? It looks like they provide power to those terminals. I also assume it's the same process of write on switch selection 1, switch to Zero, pull mini USB, switch to 3 & press reset to start?

    I will type it into SimpleIDE when Kennedy comes home from school.


    Thanks everyone for the warm welcome and will post back when we have the project completed.

    Cheers,

    -Ben
  • Courtney JacobsCourtney Jacobs Posts: 903
    edited 2015-03-16 14:02
    Yes, the jumper should be set to 5V for P16&17.

    Everything remains in place as set up originally for the ActivityBot, electronically, and the normal procedure for loading the program applies. Program on 1, switch to 0 (off), remove from USB cable, place on the ground, switch to 2 and let it roam.

    If you notice the ramping speed is too slow/fast, you can play around with it by changing its value in this line (make the value greater or lower):
    drive_setRampStep(10);                      // Set step size
    

    I have mine set to 25.
  • BenthePIBenthePI Posts: 8
    edited 2015-03-16 16:27
    Awesome Courtney.

    Time to sine! (For Kennedy at least).
  • BenthePIBenthePI Posts: 8
    edited 2015-03-17 18:17
    Courtney,

    I was able to load the code in. At first Kennedy typed it and messed up a line, so resorted to copy & paste.

    Once switch 2 is on the robot looks to the right and backs up until it's picked up and that's the extent of the program.

    Cheers,

    -Ben
  • BenthePIBenthePI Posts: 8
    edited 2015-03-17 18:24
    I did make 2 changes to the code (after it didn't work) not sure if they were mistakes.

    Line 23 changed 1800 to 180.
    Line 43 changed 900 to 90, however the program had the same result.

    Is there a resin the angle has an extra zero?
  • twm47099twm47099 Posts: 867
    edited 2015-03-17 20:25
    BenthePI wrote: »
    I did make 2 changes to the code (after it didn't work) not sure if they were mistakes.

    Line 23 changed 1800 to 180.
    Line 43 changed 900 to 90, however the program had the same result.

    Is there a resin the angle has an extra zero?

    I haven't had a chance to try the code on my ActivityBot, but the angle for the servo function is in tenths of a degree. That way you can work with integers (smaller code) and still have 1/10 degree resolution for the servo. (So 1800 is the scaled version of 180.0 degrees, or 180.0 * 10 degrees).
    .
    Tom
  • BenthePIBenthePI Posts: 8
    edited 2015-03-17 23:12
    You know…that makes sense Tom.
  • BenthePIBenthePI Posts: 8
    edited 2015-03-18 02:06
    I changed lines

    23 to 1800
    28 to 1800
    43 to 900

    Now the servo rotates to the left and it goes forward about a 2 Ft & ticks forward a cm every 2-3 seconds.

    If not anything it's interesting to see how the change in code reacts when loaded.
  • twm47099twm47099 Posts: 867
    edited 2015-03-18 08:10
    BenthePI wrote: »
    I changed lines

    23 to 1800
    28 to 1800
    43 to 900

    Now the servo rotates to the left and it goes forward about a 2 Ft & ticks forward a cm every 2-3 seconds.

    If not anything it's interesting to see how the change in code reacts when loaded.

    Try changing the drive_rampstep to drive_ramp and add a short "pause(time)" after it. Otherwise try increasing the drive_setramp () value as Courtney suggested (try this first, before changing drive_rampstep.) I haven't used drive_rampstep in any of my programs, so I'm not quite sure how it works, but from the program I think it increases the speed per step and runs one step??

    Tom
  • twm47099twm47099 Posts: 867
    edited 2015-03-18 08:22
    I found where the drive_rampstep function is described. It's at the link below.

    http://learn.parallax.com/activitybot/roaming-infrared-flashlights

    Either increase the step size or make sure that the loop repeats quickly enough so there is smooth motion.

    hope this helps
    Tom
  • Hey guys,

    I copied and pasted this code but I keep getting build error. Any suggestions?
    Thanks!
  • I'd suggest reading the red text at the bottom of the screen to see what the build error is.
  • twm47099twm47099 Posts: 867
    edited 2016-05-25 04:42
    dbd16 wrote: »
    Hey guys,

    I copied and pasted this code but I keep getting build error. Any suggestions?
    Thanks!

    I just tried copying (cutting & pasting) the code from Courtney's post above into SimpleIDE. Then I tried building it by clicking on the hammer icon (I'm away from where I have my activitybot). It built without any errors.

    Make sure that when you cut & paste that you select all of the code (scroll down) and nothing else.

    Tom
  • Mike GreenMike Green Posts: 23,101
    edited 2016-05-25 14:33
    Here's a link to a version of FemtoBasic for the Activity Board (and the Activity Board on a BOEBot chassis with the PING). There's a version of Roaming with BOEBot for this configuration included.
  • Thanks guys!
    I restarted my computer and ran it again, and now it works perfectly.
  • WhitWhit Posts: 4,191
    Yay! Glad you got it solved dbd16!
Sign In or Register to comment.