Puzzling differences between PUB / PRI variables
lardom
Posts: 1,659
"Global variables initialize to zero." I read that rule yesterday and moved all my local variables to the VAR block because I was seeing strange values displayed on the PST. I then lost the ability to make my steppers start and stop at the same time. I didn't see why I was having problems right away because I rename objects "V1, V2 and so on whenever I add new features and I was looking for a typo. I eventually made the variables local again.
I'm working on differentially steering two steppers and I was trying to add a ramping feature. It appears that if you use cognew then you should stick with local variables if timing is important.
Can anyone explain why local variables are not zero by default?
I'm working on differentially steering two steppers and I was trying to add a ramping feature. It appears that if you use cognew then you should stick with local variables if timing is important.
Can anyone explain why local variables are not zero by default?
Comments
-Phil
My guess is that the same method is being started in the same object more than once. As such the variables being moved out of local (to the method) now exist in one instance in VAR and the two running instances of the method are fighting over them.
This is probably nothing to do with initializing to zero or not.
Can't tell unless we see the code.
My object causes two steppers with a wheelbase of 13" to travel in an arc of a given radius. Pi (Tau) is used in the equation and the two steppers start and stop at the same time. I used cognew for both motors. I tried to add a ramping feature in "Version 3" which I'm working on right now.
I don't follow what you mean by "...cog variable isn't set to anything". I do remember an issue where the motor pulses seemed to get weaker and I thought a value was overflowing but I couldn't find the source of the problem. I wonder if that was the cause.