
I get what you mean now, the while loop can exit but leave a motor turned on based on the way the if statements panned out.Īlternatively I think you can also hack this to work if you create two separate ints for the LE and RE that get updated at the beginning of the while loop and then do your if statements. The motors need to be turned off after the while loop, as that means the turn should be completed at that stage. I started writing out all of the cases and you are 100% right.
#ROBOTC ENCODER CODE#
This would be manageable, except this project I'm doing this code for requires 4 consecutive point turns. Only with this point turn code does it wack out and not work.

What could my problem be with this? Is it an issue with the brain of the robot? Everything is plugged in correctly by the way, and the straightening function that I have on it runs beautifully. This is problematic for obvious reasons and I'm coming here because I'm out of other options: we put spacers in between the wheels and encoders, replaced our original left encoder with a brand new one, etc. The left wheels spin backwards, the right ones forwards, right? However, every other time we turn our robot on (it's just a squarebot) the left wheel stops not at -360 but closer to -1700, meaning it keeps spinning while the right wheel is immobile. Minor errors I made here aside, one would assume that with this program it'll execute a left point turn. (For reference: leftEncoder refers to the left motor which is in Port 3 and needs to move in reverse, rightEncoder refers to the right motor in Port 2 which needs to move forward, I'm also using only 2 motors for this)

I need to write a point turn for my robot using the quadrature shaft encoders, and the code for that I have (as best as I can remember it) looks something like:

For my Robotics class we use RobotC with the PIC 0.5, not the Cortex.
