Let's Make Robots!

Problem on the Picaxe softwere

Well, some days ago ago i was happily writing a code on the Picaxe programming editor when an unexpected problem showed up.

The problems came when i started to simulate my code: after some time this thing appeared:


What does it mean? What i can do to avoid it?

Thanks for the future answers

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Eg. The on the PICAXE 08M you can maximum have 15 gosub, on the PICAXE 18X you can have 255 gosub’s

i am working on a picaxe 28x1!

And i don't have many gosub...no more than 50.

Maybe they are nested to deep. So that one gosub calls another gosub and so on? I think it all adds up in some sort of ‘gosub stack’.

Do you have a sub routine A that calls routine B that then calls routine A again?


Maybe your code gets stuck in a loop like this and runs out of stack space?


Without seeing the entire code it is hard to tell. 

probably it is. But i dunno how to solve it.

I cannot think to another way to do this! Currently, I'm tring to make the " servo head" turn from 100 to 200 and than back from 200 to 100 while it is reading the distance.


symbol servohead= 1
symbol IRfinder=0
symbol servoangle= b0
symbol range=b1
symbol dangerlevel1=70
symbol dangerlevel2=90
symbol ultradanger=110

for servoangle= 90 to 210 step 10
servo servohead,servoangle pause 100
readadc IRfinder, range
if range>dangerlevel1 then
gosub detection
gosub straight

next servoangle                                        ' Perheps here is the problem-

for servoangle= 210 to 90 step -10
servo servohead,servoangle pause 100
readadc IRfinder, range
if range>dangerlevel1 then
gosub detection
gosub straight
gosub angle                                             'and here
goto main


next servoangle                                 ' I have done this gosub because in the other parts of the code, sometimes       

                                                          i have to go back into the "next" command without starting over from the main.


That's why i use many times the command "gosub". I have tried to put "next servoangle" instead, but the syntax doesn't allow me to do it, saying that "next without for"

Can you think about any solutions? By the way, thank you very much for your answers

Your program has a flaw in its structure. You have a subroutine calling itself. Like a dog chasing its own tail.

You really should decide what it is you need your servo to do. And when. And under which conditions. You need a flow chart of your robot's actions and decisions. And you need to make it as simple as you can make it.

Then write it in basic code. Simulate it or test it on your robot. Make it work. Just make the servo point all the way left, then right, then repeat. Then write variations for that. Until you have something you need. Keep testing as you make changes. And keep an eye on your flow chart.

There are more flaws in your code. I cannot point hem all out to you. Besides, that would not be very helpful to you. You do not have a bug in your code. The entire structure is missing. Without a plan, every program is doomed. Doom is not a bug.

Forget about the subroutines. Write stupid code first. Structure the stupid code. Check the chart. Then you will find that you copy/pasted pieces of code to make it work. Does the code work? Then (and no sooner) it is OK to move the repeated code to a subroutine.

One more picaxe specific pointer: read the manual on the commands "servo" and "servopos". You need to use them both. Read the manual about the reasons why.

Good luck!

Thank you very much. I will try to figure out something following your instructions. Actually, i have never tried to work with a flow char, but it's time to start! It's a good idea. Yes, you are right, there are many flaws in my code!

Thank you guys again, your help is really appreciated