I was wondering how to program the Optical Shaft encoders (not the quad shaft encoders…) and how to set up more than 1 of them in the variables table… meaning having one encoder for each side of the robot… left and right…
I am curently using the newest version of EasyC V2 and am also using the old vexnet adapter… i have learned robotC and from that i learned that the encoders should be in pair with the motors meaning that if a motor is in motor port 1 the encoder should be in analog/digital port 1(i also dont understand the analog/digital either…) my question is i want it to have the robot run the autonomous but on the driving portion use the input of the encoders to be more accurate… i cant seem to figure out how to get the robot to get out of the loop and move on to the next command… i dont understand where to start the encoder and where to preset it bc i would have to use the encoder multiple times… as in go forward(using encoders) then raise arm(no encoder) lower arm(no encoder) then go backward (using encoder)… etc… Also when would i want to stop all input form the encoder
also same with the limit switches i have got it to work in a while loop that is forever such in user controll but in the autonomous i cant get the robot to, when the limit is hit to stop the motors and run the next command…
Can someone please help by giving me an example on how to set any of these up… or anything would be nice.
Well I dont know much about EasyC because we stopped using it after the first competition in new zealand. it was a real bummer program, not enough power. anyway I can give you a few tips because these apply to both easyC and RobotC.
for stopping loops: inside the loop have an if statement that will be used to determine when you want it to stop, and inside that if statement have break.
this example shows you how to stop the infinite while loop after the encoder has made more than or equal to 1000 ticks.
if (example_encoder1 >= 1000)
with the encoders, there should be commands which reset them, when they reset they are put back to 0, so at the top of each autonomous step, reset the required encoders and then continue, this way you only have to program from 0.
for the limit switches, just do the same from the first tip but in the if statement, have something like this instead:
if (limit_switch == 1)
analog and digital are two different things, its in the waveform but we wont get into details. You just need to know that analog sensors provide numbers of any range while digital sensors provide only on/off (1/0).
encoder is analog, limit switch is digital.
My understanding is that encoders are digital. This is because they don’t actually sense a large range of values, they only return 1s and 0s (highs and lows?) to the microcontroller, depending on whether the infrared light inside is shining shrough the rotating slotted disk. The program then counts these changes to give the range of values we see. Please correct me if I’m not understanding this properly
magicode’s code is useful and is another way of doing it but it may not be the most efficient, it depends on what you want.
also, RobotC does have something like the “get encoder” block, but you dont use it the same, you just copy the value from an array instead.
The code I wrote was for example purposes only, do not expect it to work straight-out-of-the-box. The syntax is correct, you just need to edit it to include what you need and to edit the variables for the respective platform.