Let's Make Robots!

Small change in picaxe code makes things twitch

Hi LMR,

I have my Rommel setup and hooked up some leds. So far all fine. Using the code from Lets start here I added a high 2 and high 3 (and low again) to make the leds blink in the direction the bot is turning. Like here;

rturn:
high 3
servo 0, 105 : servo 1, 195
low 3
return

lturn:
high 2
servo 0, 195 : servo 1, 105
low 2
return

totalhalt:

When I add these 2 the led blinks briefly but then the servo's start to jitter when it moves forward? Lights are off by then....

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Welcome in the magical world of picaxe basic! I cannot explain it either. Just some observations:

I see no pause in the subroutine. How long did you expect the LED to stay lit?
The command "servo" is used to setup a servo pin and initial servo position. Subsequent changes in position should be programmed using the command "servopos". This is something to do with timer counters resetting. Check manual 2.
Do the servos jitter when you fire the main motor(s)? Did you exclude electrical noise as a cause yet?

Hola Rik.

The LED just flashes very briefly. If  add pauses like "wait 1" it goes weird as if it's using the pause in its no danger routine.

Ok on the servo command. Seems to work but I'll change it.

That's the thing. The LED's just flash on and off. Then it goes into the no danger routine and when it's driving it starts to jitter. If I don't flash the LED's all works fine. As if there's some signal echoing back. But delayed a little.

They tell you how to do something the "right way, but often fail to explain why that way is so right. Good chance you will get rid of the jitter by replacing the servo commands with servopos. Make sure to test one code change per experiment or you will go mad.

Oh, why am I lecturing you. Mouse click engineers....

Because your the best. It worked. Cheers you penguin loving nerd ;)

See: nobody explained you why to change it, but it helped anyway. Typical Picaxe. Should suit you fine ;-)

Hi! there,  I was reading your post and it's interesting to fit these lines in an existing code but......where do you add those?? For example if I use the start here robot code and I want to inserted leds/sound,how do I know between which lines and gosubs commands? I'm learning thru you guys. Thanks.

In the code supplied by Frits (start here robot) you have to sections, 1 where it makes the actual turn and 1 where it turns it head. Mine drives the head lights on (no danger) and blinks when taking a turn. It flashes the lights before it starts (to give me some time and unhook it from the cable). Leds are on 2 and 3. Looks like this;

high 2 : high 3
wait 4
Servo 0,150 : Servo 1, 150
low 2 : low 3
wait 1
high 2 : high 3
wait 1
low 2 : low 3
wait 1
high 2 : high 3
wait 1
low 2 : low 3
wait 1
high 2 : high 3
wait 1
low 2 : low 3

Symbol dangerlevel = 90 ' how far away should thing be, before we react?
symbol turn = 400 ' this sets how much should be turned
symbol servo_turn = 500 ' This sets for how long time we should wait for the servo to turn (depending on it´s speed) before we measure distance

main: ' the main loop
readadc 0, b1 ' read how much distance ahead
if b1 < dangerlevel then
gosub nodanger ' if nothing ahead, drive forward
else
gosub whichway ' if obstacle ahead then decide which way is better
end if
goto main ' this ends the loop, the rest are only sub-routines


nodanger:' this should be your combination to make the robot drive forward, these you most likely need to adjust to fit the way you have wired your robots motors
high 4 : low 5 : high 6 : low 7 : high 2 : high 3
return


whichway:
gosub totalhalt ' first stop!

'Look one way:
gosub lturn ' look to one side
pause servo_turn ' wait for the servo to be finished turning
readadc 0, b1
gosub totalhalt


'Look the other way:
gosub rturn ' look to another side
pause servo_turn ' wait for the servo to be finished turning
readadc 0, b2
gosub totalhalt

' Decide which is the better way:
if b1<b2 then
gosub body_lturn
else
gosub body_rturn
end if
return

body_lturn:
low 4 : high 5 : high 6 : low 7 ' this should be your combination that turns the robot one way
pause turn : gosub totalhalt
return

body_rturn:
high 4 : low 5 : low 6 : high 7 ' this should be your combination that turns the robot the other way
pause turn : gosub totalhalt
return

rturn:
servopos 0, 105 : servopos 1, 195
wait 1
low 3
return

lturn:
servopos 0, 195 : servopos 1, 105
wait 1
low 2
return

totalhalt:

low 4 : low 5 : low 6 : low 7 ' low on all 4 halts the robot!
Servopos 0,150 : Servopos 1, 150
wait 1 ' freeze all for one second
return

Thanks for your kindness :)   But one dummed question for you...

Servo 0,150 : Servo 1, 150   are these for 2 servos(0 and 1) and indicates the pin where the servo is connected?

Yes, Rommel (that uses this code) has 2 servos on pin 0 and 1 (the hands). The leds are on 2 and 3. His head is attached to 1 of the servos that moves its hand.

Ah ok then I was right :)  Thanks for your reply. Actualy on my start here robot II, I am running the clean_navigator from Frits,they only difference between the one is the SRF05 instead of the sharp. The robot doen't stop in front of an object,it keeps moving,which I like. Have to fill the lines in the code for leds and sound etc... I guess the use of gosubs  is what I need.

Keep up your good work,your robots are cool :)