I have code that uses a calculation using gyros in a forever loop. The purpose of the code is to turn a direction until goal is reached. But the code is just stuck in forever loop. I have played around calculations, did not help. How can I troubleshoot what is breaking in my forever loop? New to this programming. Thanks for any help
The pro forumers can’t help you with your code if they can’t see it. Copy and paste it here or take a screenshot of it so the can see where the bugs are.
The code is just stuck in the forever loop. I have added wait, used a variable instead of calculations. what else I can try?
forever
loops last, as the name implies, forever. The program will stay in the loop until you tell it to leave with a break
block, and right now you never tell it when to stop looping
To let your code leave the loop you need to either use a different type of loop which has an exit condition, like a while
loop, or you need to run the break
block when you want the loop to end.
I made another version of the code. My goal is for precise left turn. I used the following - and the set Left motor calculation does nothing . How can I figure if this calculation is incorrect?
the spinFor command will stop the motor when it’s completed its task. What you want to be doing is setting your velocity while you are moving your motor. What you’re actually doing is moving your motor for x degrees and then changing the velocity after it’s stopped. Also, why are you spinning your left motor for heading
degrees? They’re two very different types of degrees and they probably should not be used together like that.
Thanks Elephanf - I am also working on this code that I got from an online tutorial. I can get the robot to move straight now, but somehow my turns are getting stuck in the loop. I have tried to reverse the + -. What else can I possibly try here.
I had this issue a lot before too. I didn’t really end up solving it, unfortunately. What I will ask, though, is why you are using the momentum value? It honestly seems to me like you don’t need to use it and it will just complicate your code further.
I do know that what is happening is that your while loop’s parameters are being constantly engaged - I believe most likely to do with your inertial’s heading values.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.