PDA

View Full Version : PINGs on robot freezing?? Servos are not to blame! HELP ME!!!



Microcontrolled
05-24-2010, 07:25 AM
Sorry for the odd title. I have a robot that I have built that has 2 PING's, an Xbee, an SD card and audio out. The robot is moved by 2 Parallax continuous rotation servos. I am powering it all off 4 D cells. The robot will relay sensor information back to the home through the Xbee, and the home commands the robot with simple 1 byte serial commands. My problem is: The ping's will be working for a while, then all of a sudden the lights will stop flashing and data will stop being returned. I can't figure any reason for this happening, as I once thought that it was the servos, but after isolating the servos from the program and making my own servo driver, and I made both a serial and analog one, it still happened. I then tryed decresing the speed of the reads on the PINGs. No luck. I've tryed everything that I can think of and there still seems to be no rhyme or reason to what is happening. I am using Kye's duel servo driver and the default PING driver. I know that it is not the home end because it acts the same if controlled by typing the commands in on a PC terminal. Can someone help?? Here's the code:




''This is version 2 of the RC bot. This version allows it to be fully automated, and turned on and off
''(the automation) from the transmitter. It can not be turned back manuel from the remote at this
''time. The RC bot also features a park function (2 PINGS needed) that will park itself in a corner and
''sleep until the sound sensor is triggered.
''
''Version 2.2 has lots of added wireless commands that give the controller full power and monitoring
''over the robot.
''Version 2.3 corrects a bug that was case conflicts on the incoming characters. Now they have been moved
''to hexadecimal values.
''Version 2.4 lets the control see values bigger then a byte length by changing the value from inches
''to feet automatically and by adding in a type byte.
''Version 2.5 removes the features of 2.4 due to no functionallity, and it improves the autopilot by
''allowing it to use both the front and side sensor to know what direction to turn, or if it is drifting
''into a wall due to slightly unbalenced servos.
''Version 2.6 removes conflicting between the PINGs and the rest of the program by putting them in a
''seperate cog.
''Version 2.7 added FSRW and Rayman's WAV player. Also have adapted code to use the SD/sound card
''I built for the robot.
CON

_CLKMODE = XTAL1 + PLL16x
_XINFREQ = 5_000_000 '80Mhz clock rate

Ppin = 0
speed = 0

buffSize = 100

VAR

long state
long cstate
long stack[20]
long minutes, seconds
byte time
long dist
long side
byte type

''///////////WAV player vars////////////////////////////////////////////////////

long parameter1 'to pass @buff1 to ASM
long parameter2 'to pass @buff2 to ASM
long parameter3 'to pass sample rate to ASM
long parameter4 'to pass #samples to ASM
long buff1[buffSize]
long buff2[buffSize]
byte Header[44]

OBJ

servo : "servoEngine"
ping : "Ping"
xb : "Xbee_Object"
sd : "fsrw"

PUB Start | i, cntn

xb.start(8,9,0,9600)
servo.servoEngine
time := 5
sd.mount(16)

cognew(GetPing,@stack)
Manuel

PUB Manuel

' state := @idle
'cstate := @man
servo.SetPositionA(90)
servo.SetPositionB(90)
' Automatic
repeat
case xb.rx
"u":
xb.tx($FA)
servo.SetPositionA(0+speed)
servo.SetPositionB(180-speed)
'state := @active
"d":
xb.tx($FA)
servo.SetPositionA(180-speed)
servo.SetPositionB(0+speed)
'state := @active
"r":
xb.tx($FA)
servo.SetPositionA(180-speed)
servo.SetPositionB(180-speed)
'state := @active
"l":
xb.tx($FA)
servo.SetPositionA(0+speed)
servo.SetPositionB(0+speed)
'state := @active
$FD:
xb.tx($FA)
servo.SetPositionA(90)
servo.SetPositionB(90)
'state := @idle
$0A:
reboot
$0B:
time := xb.rx
' $0C:
' speed := xb.rx
$0D:
'state := @dormant
Nap
"i":
waitcnt(clkfreq/50 + cnt)
xb.tx(dist)
xb.tx(side)
xb.tx(speed)
xb.tx(ina[10])
"I":
waitcnt(clkfreq/50 + cnt)
xb.dec(dist)
xb.dec(side)
xb.dec(speed)
xb.dec(ina[10])
"a":
xb.tx($FA)
cognew(Timer,@stack)
Automatic
$0F:
waitcnt(clkfreq/50 + cnt)
xb.str(string("Distance from objects: "))
xb.dec(ping.Inches(Ppin))
xb.str(string(13,"State: "))
xb.str(state)
xb.str(string(13,"Control: "))
xb.str(cstate)


PUB Automatic | count

servo.SetPositionA(0)
servo.SetPositionB(180)
repeat
if xb.rxcheck == "M"
Manuel
if xb.rxcheck == "P"
Park
if side < 6
servo.SetPositionA(180)
servo.SetPositionB(180)
waitcnt(clkfreq/3 + cnt)
servo.SetPositionA(0)
servo.SetPositionB(180)
if dist < 36
side := ping.Inches(1)
if side < 48
servo.SetPositionA(180)
servo.SetPositionB(180)
else
servo.SetPositionA(0)
servo.SetPositionB(0)
repeat
dist := ping.Inches(Ppin)
waitcnt(clkfreq/100 + cnt)
count++
if count == 700
Start
if dist > 48
Automatic
if minutes == time
Park

PUB Park | edge

servo.SetPositionA(0)
servo.SetPositionB(180)
repeat
waitcnt(clkfreq/100 + cnt)
if dist =< 12
quit
servo.SetPositionA(180)
servo.SetPositionB(180)
repeat
waitcnt(clkfreq/100 + cnt)
if side =< 15
quit
servo.SetPositionA(0)
servo.SetPositionB(180)
repeat
waitcnt(clkfreq/100 + cnt)
if side =< 10
servo.SetPositionA(180)
servo.SetPositionB(180)
waitcnt(clkfreq/20 + cnt)
servo.SetPositionA(0)
servo.SetPositionB(180)
if side => 13
servo.SetPositionA(0)
servo.SetPositionB(0)
waitcnt(clkfreq/20 + cnt)
servo.SetPositionA(0)
servo.SetPositionB(180)
if side > 18
Park
if dist <= 12
Sleep

PUB Sleep

repeat
waitcnt(clkfreq/20 + cnt)
if ina[10] == 1
Automatic

PUB Nap

dira[12]~~
outa[12]~
repeat
waitcnt(clkfreq*2 + cnt)
outa[12]~~
waitcnt(clkfreq/300 + cnt)
outa[12]~
if ina[11] == 1
quit
return true

PRI GetPing

repeat
dist := ping.Inches(Ppin)
side := ping.Inches(1)
waitcnt(clkfreq/20 + cnt)

PRI Timer | dT, T

dT := clkfreq
T := cnt

repeat
T += dT
waitcnt(T)
seconds ++
if seconds == 60
seconds~
minutes++




As you can see the sound and SD card are not used in this program.

Thanks in advance,

Micro

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my new website!! (http://microcontrolled.propmodule.com/home.html)

Use the Propeller icon!! http://www.proptools.org/images/Propeller.gif

Follow me on Twitter! Search "Microcontrolled"

Mike Green
05-24-2010, 07:41 AM
How are you powering the servos? Are you running them directly off the battery or are you using the regulated 5V supply? If it's the 5V supply, you may be overheating the regulator with the servo current drain on top of the PINGs and the regulator is shutting down

Microcontrolled
05-24-2010, 07:54 AM
Could that be it? 6V is safe, so I'll try running them at VIN.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my new website!! (http://microcontrolled.propmodule.com/home.html)

Use the Propeller icon!! http://www.proptools.org/images/Propeller.gif

Follow me on Twitter! Search "Microcontrolled"

Microcontrolled
05-24-2010, 08:08 AM
No, that did not fix it. However, I think that that might (and that's a big might) be what is causing it. The first couple of tests the PINGs would work until the servos were on, then they would resume working 2 seconds after I stopped the servos. After a few tests, though, they started just staying off once the servos were on. It does definitely involve the servos, but it could be software or hardware.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my new website!! (http://microcontrolled.propmodule.com/home.html)

Use the Propeller icon!! http://www.proptools.org/images/Propeller.gif

Follow me on Twitter! Search "Microcontrolled"

Sparks-R-Fun
05-24-2010, 08:16 AM
How confident are you that your batteries are not weak?

ии- Sparks

Timmoore
05-24-2010, 08:20 AM
2 comments about the software, stack size of 20 is pretty small, I would try much larger until you are sure you have no problems.
The ping and timer cogs use the same stack - will cause problems, you need 2 stacks one for each.

Timmoore
05-24-2010, 08:20 AM
2 comments about the software, stack size of 20 is pretty small, I would try much larger until you are sure you have no problems.
The ping and timer cogs use the same stack - will cause problems, you need 2 stacks one for each.

Microcontrolled
05-24-2010, 08:36 AM
I don't think the batterys, as they are new, but I will try a new pair tomorrow. The PINGs freeze even if the read commands are called and are not in a seperate cog. That is not the case.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my new website!! (http://microcontrolled.propmodule.com/home.html)

Use the Propeller icon!! http://www.proptools.org/images/Propeller.gif

Follow me on Twitter! Search "Microcontrolled"

Mike Green
05-24-2010, 08:40 AM
Timmoore has a good point. You can't use the same stack area for two cogs. You have to have a stack area for each cog.