Stingray Ping PID follower
This is a Stingray PID follower demo using the dual pings setup (thanks Tony B.!) for left and right distance measuring. This demo shows the Stingray following an empty Parallax shipping box @ 10 inches.
For anybody that setup the pings on their Stingray like Tony B. showed in this thread- http://forums.parallax.com/showthread.php?123541-New-Take-on-Pings-for-the-Stingray give this a try. (setting up the proper i/o pins for the pings and their servos in the Con section for your robot)
So far I have added this ping setup, set of motor encoders, ir receiver, rf transceiver, network camara, an arm/gripper, and a 7.2volt 5000mah LiPo battery to my Stingray. All you need though to try this demo
is the Stingray and the ping setup. Download the stingray pid follower.zip file, unzip and click on stingray pid follower.spin. Merry Christmas and Happy New Year to every one!
http://www.youtube.com/watch?v=FlKa65Ui1Xc
For anybody that setup the pings on their Stingray like Tony B. showed in this thread- http://forums.parallax.com/showthread.php?123541-New-Take-on-Pings-for-the-Stingray give this a try. (setting up the proper i/o pins for the pings and their servos in the Con section for your robot)
So far I have added this ping setup, set of motor encoders, ir receiver, rf transceiver, network camara, an arm/gripper, and a 7.2volt 5000mah LiPo battery to my Stingray. All you need though to try this demo
is the Stingray and the ping setup. Download the stingray pid follower.zip file, unzip and click on stingray pid follower.spin. Merry Christmas and Happy New Year to every one!
http://www.youtube.com/watch?v=FlKa65Ui1Xc
Con ''Stingray ping PID follower by Dave Ratcliff "ratronic" 12/24/10 (with forward facing left and right ping sensors)
_clkmode = xtal1 + pll16x ''setup propeller clock @80mhz (5mhz crystal * 16pll)
_xinfreq = 5_000_000 ''
lps = 13 ''left ping servo i/o
rps = 12 ''right ping servo i/o
lpg = 15 ''left ping i/o
rpg = 14 ''right ping i/o
rsp = 100 ''robot wheel speed
pwm = 24 ''pwm base i/o (for stingray's wheel motors)
Obj
pd[2] : "pid" ''pid left and right objects
pg : "ping" ''ping sensor object
pw : "pwmx8" ''pulse width modulation object
sr : "servo32v5" ''servos object
Var
Pub main | l, r, lp, rp
''initialize
pw.start(pwm, %00001111, 23_000) ''start pwm object on base i/o for stingray wheel motors drive pins @ 23khz
sr.set(lps, 1000) ''set left ping servo looking forward
sr.set(rps, 1500) ''set right ping servo looking forward
sr.start ''start servo object
''kp, ki, kd, setpoint, offset, max area, min area
pd[0].init(-40.0, -3.0, -1.0, 10.0, 0.0, 0.0, 0.0) ''initialize pid object for left side following @ 10 inches
pd[1].init(-40.0, -3.0, -1.0, 10.0, 0.0, 0.0, 0.0) ''initialize pid object for right side following @ 10 inches
''main loop
repeat ''keep repeating instructions below
l := pg.inches(lpg) ''get left ping sensor distance in inches
waitcnt(clkfreq/100 + cnt) ''delay 10ms before next ping distance check (echo reduction)
r := pg.inches(rpg) ''get right ping sensor distance in inches
lp := pd[0].calculate(l) ''get pid motor calculation for left side
rp := pd[1].calculate(r) ''get pid motor calculation for right side
lp := -rsp #> lp <# rsp ''limit left pid motor calculation to rsp constant
rp := -rsp #> rp <# rsp ''limit right pid motor calculation to rsp constant
move_robot(lp, rp) ''set stingray's left and right wheel speed from pid motor calculations
Pub move_robot(left_wheel, right_wheel) ''set the speed of stingray's left and right wheels, -255 max.reverse to 255 max.forward, 0=stop
left_wheel := -255 #> left_wheel <# 255 ''limit left_wheel motor speed from -255 to 255
right_wheel := -255 #> right_wheel <# 255 ''limit right_wheel motor speed from -255 to 255
ifnot left_wheel & $80_00_00_00 ''check sign bit for left_wheel motor speed amount
pw.duty(pwm + 1, left_wheel & $ff) ''set pwm output for left_wheel base pin + 1 limited to 255
pw.duty(pwm, 0) ''set pwm output for pwm base pin to 0
else
pw.duty(pwm + 1, 0) ''set pwm output for pwm base pin + 1 to 0
pw.duty(pwm, (0 - left_wheel) & $ff) ''set pwm output for left_wheel base pin limited to 255
ifnot right_wheel & $80_00_00_00 ''check sign bit for right_wheel motor speed amount
pw.duty(pwm + 2, right_wheel & $ff) ''set pwm output for right_wheel base pin + 2 limited to 255
pw.duty(pwm + 3, 0) ''set pwm output for right_wheel base pin + 3 to 0
else
pw.duty(pwm + 2, 0) ''set pwm output for right_wheel base pin + 2 to 0
pw.duty(pwm + 3, (0 - right_wheel) & $ff) ''set pwm output for right_wheel base pin + 3 limited to 255


Comments
Awesome!!! Great work with the Stingray. I'm so glad my ping idea has worked so successfully for you. I hoped it would inspire others and get the ball rolling on developing good software for the Stingray. I had to lay off from working on robotics this summer and fall, but now I am able to get back to work. I will try running your code this week. Could you post more pictures and info on your robot? The description and video have me eager to see more and I could use a little inspiration.
Thanks for sharing your work!
Tony
Hi,
Is there a bs2 version?
thanks