Combining codes of Ping))) Sensor and Servo connected to Propeller Board inside S2
ASDevaraju
Posts: 8
Hi, I am currently working an S2 robot with a Propeller Board inside(I remember it being a Propeller BOE). The external hardware added to the robot are the PING))) Ultrasonic Sensor and the Servo(Parallax Standard Servo). I am currently stuck on programming both the sensor and the servo to work at the same time. Here are the codes for the Ping))), The servo, and for the final code, respectively: PING_TEST:
S2_SERVO_TEST:
And the PING_SERVO:
CON _xinfreq = 5_000_000 _clkmode = xtal1 + pll16x PING_PIN = 5 PCBAUD = 115_200 obj d : "Parallax Serial Terminal" ping : "Ping" PUB Go d.start(PCBAUD) repeat d.home d.str(string("Ping distance: ")) d.dec(ping.Millimeters(PING_PIN)) d.str(string(" mm ")) PauseMs(20) pub PauseMs(duration) waitcnt(cnt + (clkfreq/1000)*duration)
S2_SERVO_TEST:
con _xinfreq = 5_000_000 _clkmode = xtal1 + pll16x SERVO_PIN = 4 pub RunServo 'set pin to be an output dira[SERVO_PIN]~~ repeat PulseOut(1000, SERVO_PIN) PulseOut(1500, SERVO_PIN) PulseOut(2000, SERVO_PIN) pub PulseOut(time, pin) repeat 100 outa[pin]~~ waitcnt(cnt + (clkfreq/1_000_000)*time) outa[pin]~ PauseMs(20) pub PauseMs(duration) waitcnt(cnt + (clkfreq/1000)*duration)
And the PING_SERVO:
CON _xinfreq = 5_000_000 _clkmode = xtal1 + pll16x PING_PIN = 5 PCBAUD = 115_200 SERVO_PIN = 4 obj d : "Parallax Serial Terminal" ping : "Ping" PUB Go d.start(PCBAUD) repeat d.home d.str(string("Ping distance: ")) d.dec(ping.Millimeters(PING_PIN)) d.str(string(" mm ")) PauseMs(20) pub RunServo 'set pin to be an output dira[SERVO_PIN]~~ repeat PulseOut(1000, SERVO_PIN) PulseOut(1500, SERVO_PIN) PulseOut(2000, SERVO_PIN) pub PulseOut(time, pin) repeat 100 outa[pin]~~ waitcnt(cnt + (clkfreq/1_000_000)*time) outa[pin]~ PauseMs(20) pub PauseMs(duration) waitcnt(cnt + (clkfreq/1000)*duration)My classmate told that the main function to work on is the PulseOut function in order to get both the Ping)) sensor and the Servo to work, but I am still unsure.
Comments
In essence what you will need to do is have a main routine that continuously executes the ping code, the pulse out code, and whatever other code you need in a repeat loop.
Also, when you post code, use the # icon.
I was thinking of coding methods in the program. Here is what it would be:
I haven't implement the code yet. But, I know that if I were to methods, then I will need to put callMethod in a loop so it does things more than once. Any suggestions to this?
Post again and let me know how you did.
I forgot to mention to look at the README file first to see the top object.