I’m teaching myself how to use RobotC and I’ve got a program mostly written out but it starts going wrong when I try to use the motor encoder. When it gets to line 87 the robot drives forward indefinitely. I’m extremely new to coding, so if someone could look at it and show me where I’m going wrong that would be awesome.
Have you checked in the debugger windows if the encoder is actually going backwards (as in giving a negative value)?
Also, after the while loop, I think you are supposed to set your drive motors to 0, so they stop moving.
So the IME is on the motor plugged into port1, your assumption is that when sending 127 to that motor the encoder will increase it’s counter. Now I notice that you also have this motor reversed but have not reversed the other left motor. So my guess is that this two wire motor is plugged in backwards. The correct way to plug in a 2 wire motor (port1 or 10) is with the red wire towards the inside of the cortex, that is, towards the VEXnet key. Reverse the wiring and then (un)reverse the motor in motor&sensors setup and that should help.
I don’t have the robot with me at the moment, but I was using the programming debug tool and I know that the encoder was counting the correct direction when I was using it. All the encoder target values I’ve got were from me driving the robot and reading the sensor from RobotC. I’ll check into the wiring when I’m around the robot next, but I’m fairly sure that it’s a programming issue.
Ok, just be careful that you use the values shown for the encoder in the motors debug window rather than the sensors debug window when using nMotorEncoder in the code, they can be different in sign.
I don’t have robot c in front of me but there’s something you should look at. Let’s step through this logically and only look at the BackLeft motor and its encoder.
Please verify in the debugger + values of motor turn into + values of the encoder.
Now you are going backwards. You start at and should be going down. You will always be less than 1800. Try while > -1800. It will be true until you get back so far.
Turns out this was the problem, along with several sign issues because of this. I didn’t know that there was a motor debug menu. Everything is working now, thanks for the help