Help with programing: Optical Shaft Encoder

Here is our code that I have been working on. I just want it to drive forward negative 1,000 counts. (Because during the encoder test sample, that was forward) We are using EasyC V4

Sorry for the variable name, it was created after working on it for four hours with the robot not moving at all. The variable is a long.
The encoders do work; they transmitted values during the sample code test. The engines also work as I drove the robot just before programming. The encoder is hooked up to an idler gear in our drive train. The gear it is attached to is a 12-tooth gear and the driver gear is a 60-tooth gear. Please, does anyone have any ideas? I am at my wits end. Our programming teacher, our coach, and our smartest programer have no clue why it does not work. Any help would be hugely appreciated.

What does the robot do when you try to run the code? Does it continue driving and never stop? Or does it simply sit there doing nothing?

It sits still and does nothing. No warnings pop up on the terminal interface (we were programming wirelessly), all that happens is the standard autonomous twitch when I activate it then nothing.

Can you check the value of “workdamnu” just before the while loop? Then you could separate out whether the problem is in managing the variable (for example, is the type declaration in error? did the initialization work properly?) or is it in the logic of checking the value and assigning motor values?

Going to sound like a complete noob here but how would I check the value before the while loop? Would not the preset set it to zero regardless? And I am positive the it is not a type declaration error. I made sure the variable was a long value, not unsign long, as the second thing I did.

One way to debug this is have it turn before you have it go forwards, and go backwards afterward. Just have it run a motor or two for a second or so. Just so you’ll know where it’s getting to in the program.


I did try doing this after the while loop. The right intake roller on the bot should have move after the while loop was finished. It never moved during the whole time. Trying it before the while loop is a good idea, I’ll be sure to try that. My opinion is that the program gets stuck in the while loop and for some reason doesn’t activate the motor.

printtoscreen is really helpful for debugging like this.

Yes I completely forgot. I’m used to ROBOTC and I’m not too familiar with easyC ways, sorry. WilliamG I’d try to use printtoscreen to debug if you still can’t solve your problem.


So I should put a printtoscreen inside in the while loop to see what values are being produced?

You could, and I would printtoscreen a few other variables that are set as the program goes along. So you could see how far the program is getting before it gets “stuck”.


Ok. So far my plan is just to get the thing to move. :rolleyes: So what if the variable value inside the loop is zero? What would your guess be at the problem?

I mean I would have various variables be set or a single variable set to different values depending on where it gets in the program. For example have a TEST variable set to 0 at the top, 1 just before the loop, 2 inside the loop, and 3 right after the loop. Then printtoscreen, run the program and see what value the variable is set to.


Ohhhhhh. Ok. Will do. Thanks alot guys! I’ll post up what I find come tuesday.

Okay great! And no problem. :slight_smile:


maybe set the variable as an “int”?
not too sure of the specifics, but that was our problem a longgggg time ago

Hey guys, just wanted to say thanks for all of your help. Got the encoder to work today. Turns out it was a hardware issue.

Can you pay it forward by posting the some details of the “hardware issue”,
so others can learn about common problems with using OSEs?

ie: forgot to plug it in, plugged it in backwards, forgot to set config, changed the ports we plugged it, wire was broken, swapped OSE and now it works, sensor axle wasn’t connected to drive train, only works when standing on left foot facing north, plugged OSE into digital in port instead of motor port, plugged OSE into uC instead of joystick, etc.

Very glad to see you figured out the problem! :slight_smile: Now I’d go ahead and do what jgraber suggested.


Ok. Well it was not a technical problem with the Optical Shaft Encoder; it was a problem with the engines. The Program map of the bot I was using and the actual setup of the engines were different. So what happens when you have one engine rotating clockwise and one engine rotating counter clockwise and both engines are hooked up to the same gear train? :o The bot does not move at all.