

Here too it looks like you're expecting the nMotorEncoder variable name to auto-magically update, where I would have expected you to need to call a function that returns an updated value, like the following: nMotorEncoder = GetEncoderCounts() Similarly, there is no function that returns an updated encoder count. For example, I would have thought you'd do something like the following: motor = 60 īut that last function, WriteMotorSpeed() never happens. I would have expected something more along the lines of a speed assignment followed by writing that speed to a function, but that second step never happens. You were NOT looking at the actual variables that control which case gets selected! Those variables are leftEncoder and rightEncoder.Īnd again, final warning - it looks like you're counting on things like motor and nMotorEncoder to be function names or keywords that do something, because otherwise it just looks like you enter an infinite loop that never actually writes any values to the motors. This is one of the tricky things with debugging - you have to be looking at the correct variables! In your video, you are looking at leftMotor and rightMotor, and what appears to be fields for those motors.

Int rightEncoder = abs(nMotorEncoder) // leftEncoder)īy adding the two lines inside the while loop, now you are checking and updating the encoder counts every time you step into a new loop. So, that said, try using the following: void GOforwards() I don't know about VEX robotics, but I'll caution you that your left and right encoders are based on nMotorEncoder and, just like how leftEncoder and rightEncoder doesn't get updated anywhere in your loop, nMotorEncoder doesn't get updated anywhere either. The exception might be if those variable names are actually protected variable names that have special meaning in your development environment - more on that later.
Robotc encoder update#
The problem seems to be that maybe you're thinking that the left and right encoder values will update automatically, but that is generally not the case. It looks like you don't ever update the encoder values after you initialize them.
Robotc encoder code#
much less why it runs off into oblivion when the code should exit the while loop once the right encoder's absolute value exceeds 2000. I am not sure why the power to the wheels never changes, or why it seems to believe that the Encoder values are equal. This is a video of the code running from the debugger windows: When I run the code my robot runs without stopping and the Encoder values diverge quickly. *!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#pragma config(Motor, port10, rightMotor, tmotorVex393_HBridge, openLoop, reversed, driveRight, encoderPort, I2C_2) #pragma config(Motor, port1, leftMotor, tmotorVex393_HBridge, openLoop, driveLeft, encoderPort, I2C_1) #pragma config(Sensor, I2C_2,, sensorQuadEncoderOnI2CPort,, AutoAssign ) #pragma config(Sensor, I2C_1,, sensorQuadEncoderOnI2CPort,, AutoAssign ) This is my code: #pragma config(I2C_Usage, I2C1, i2cSensors) Wait1Msec(waitTime) //makes the robot wait for 4 seconds.I have a standard VEX Clawbot, which I've been trying to make go straight for some time. #pragma config(Motor, motor11, Arm, tmotorVexIQ, PIDControl, driveLeft, encoder) #pragma config(Motor, motor6, RightMotor, tmotorVexIQ, PIDControl, driveRight, encoder)
Robotc encoder manual#
Other than that, I tried to follow with the instructions but was a bit overwhelmed by the different functions available on the first week of manual programming. Overall this was difficult and a bit confusing but this was my first time and now I have a better grasp of some of the functions such as the code for motors and time manipulation (Stop and Go) #pragma config(Motor, motor1, LeftMotor, tmotorVexIQ, PIDControl, driveLeft, encoder) This code however does not work due to some error that I wasn’t able to understand.
Robotc encoder how to#
We learnt to program by a program called ROBOTC which seemed difficult at start and it is but learning how to do it correctly wasn’t much of a challenge. Today we worked on programming our robots but via the long method of manual coding.
