Shop OBEX P1 Docs P2 Docs Learn Events
PING Servo with ActivityBot — Parallax Forums

PING Servo with ActivityBot

deanthornedeanthorne Posts: 5
edited 2014-08-07 19:28 in Robotics
Hi All;
Not sure if this is the correct forum for this post, so apologies if it is not.

I've been experimenting with the ActivityBot & PropC and have run into a of a road block. I have a PING sensor mounted on the PING Servo and am trying move the servo in 5 degree increments from extreme right (0 degrees) through extreme left (180 degrees). Once the sweep is complete, the servo needs to move the PING sensor to 90 degrees (centre). The code below works fine I execute it in a project from main. However, when I move this code into a sub function the then the results are erratic and the servo never centres. I have added pause statements after the "servo_angle(17, 900)" statement but it does not correct the erratic behaviour.
#include "simpletools.h"                      // Include simple tools 
#include "servo.h"
#include "ping.h"
 

 int main()                                    // Main function
 {
 

 int arDist[36], PINGangle = 0, i = -1, MaxDist = 0, Heading = 0;
 

 print("Start FindLongestRun\n");
   servo_angle(17,PINGangle);                                                // P17 servo to 0 degrees Extreme Right 0 + 3 degrees  
   pause(500);                                                               //wait for Chirp return
 print("Ready to begin Scanning\n");
  
   while(PINGangle <=1800)
     {//Start
       arDist[PINGangle/50] = ping_cm(16),PINGangle/50;                        // Get cm distance from Ping)))
       pause(100);                                                             // wait for Chirp return    
       PINGangle = PINGangle + 50;                                             
       servo_angle(17,PINGangle);                                              // move PING 5 degrees
     }//End While
     servo_angle(17,900);                                              
 print("Scaninng COMPLETE\n");  

Any Suggestions would be appreciated.

Dean

Comments

  • deanthornedeanthorne Posts: 5
    edited 2014-08-07 07:20
    OK so I forgot the first rule of Trouble Shooting. Check the POWER first. Changed the batteries and code and servos are functioning as expected.
  • Steph LindsaySteph Lindsay Posts: 767
    edited 2014-08-07 10:13
    Hey, good job on your project (and your troubleshooting!)

    Have you tried putting a piezospeaker on your board, and adding a simple beep to the start of the program? It might let you know in the future if the erratic behavior you are seeing is caused by the Propeller resetting as servo movements pull the last bit of juice out of tired batteries.
  • deanthornedeanthorne Posts: 5
    edited 2014-08-07 19:28
    Hi Steph
    Thanks for the feedback. The Piezo is a good idea. At this point I'm concentrating on core functions, but a power indicator of some sort is definitely on the top of the list for future enhancements.
Sign In or Register to comment.