Does anyone have a code thats uses both the line tracker, and shaft encoder in robot c? Which tracks the line to keep straight, and uses the encoders to stop a certain distance. ← Is this even possible in robot-c?
Yes. (Jordan 24C, aMESS) (robotC) and Titan (EasyC) all have code that do things like that in their autonomous. If you draw out a flowchart of what needs to be done, its not too hard to understand…
loop( linetracker code says angle left or right, if encoder>limit then break loop)
One of the key points for multi-step autonmous is to break it in to a series of steps. Each step is a subroutine call with parameters. Example parameters include things like actions to take: (lift arm, drive forward, turn)
and exit requirements like
- “timeout” (max time to allow for this step),
- stop when Cross a line,
- stop when encoder > value,
- stop when arm pot ~= value,
make a while loop to go until the average distance of the two shaft encoders is reached.
Get the values of the left and right sides, and compute the average.
The while loop goes until the average distance exceeds the target distance. Inside the while loop, do your normal line following course correction. But at the end of the while, get new values for left and right shaft encoders and find the new average distance traveled. Set the average variable used in the while and hit the while conditional test again.
If you are going too fast, you could be correcting a lot and traveling further than you want, so go slow. You also want to start this routine once you know you are over the line and not tryign to find it still. Trying to find the line will result in lots of movement making the error higher. You don’t want that.
You may want to make a function out of this to use over and over again. Pass in speed and target distance to travel. But only call it once you know you are on the line and in the direction of travel. Otherwise all that course correction will lead to error.
Lastly, I suggest you make a unit test program of this function to test it independently. It stinks to have to go 10 steps before you get to this new routine. You will save yourself time in the long run and can retest it at any time later. Including your functions from an included .c file means no more copy/paste errors too.
Have fun!
How will I be able to get new values for left and right shaft encoder with the vex cortex? If your going to say use the VEX LCD screen I don’t have that. D: Btw my team is using robot-c
You can use the “Variables” pane in the ROBOTC/EasyC debugger.
So will I have to have an orange cord connected to the robot the whole time?
Can robot-c do this wirelessly the debugging if I load the code onto the joystick or cortex (male-male cable)? ← Sorry I forgot how I usually download it.
Connect your Orange USB-Serial cable into your computer and the other end into the Program port on the Joystick. The you can use vexNet or a USB A-A cable to link the joystick to the robot. Once you get that open, go to the sensors window in the debugger.
While the robot is powered on, but with empty/useless code on it, push the robot forward the desired distance. When you look at the sensors window, the encoders will return the distance that they have rotated - this is your target distance. From here you can take the sample line following program and modify it for your ports or write your own line following code. take this code and place it in a while loop that checks the value of the wheel encoders.
It’s the “print to screen” block in easyC
It’s extremely useful and I use it all the time