Quadrature Encoder Issues

Hello, we have been programming our autonomous. We are using two Quad Encoders for the lift. They work fine when told to raise until a value is reached, however, it will not work when going to a negative number. Does anyone know a fix to this problem?


task autonomous()
{
	
	SensorValue(dgtl1) = 1;
	wait1Msec(1000);
	lift(127, 100);
	untilEncoderCounts(-40, dgtl2);
	untilEncoderCounts(35, dgtl4);
	stoplift();
	drive(63, 63, 63, 63);
	wait1Msec(1200);
	stopdrive();
	lift(127, 100);		//This is the line thats causing problems
	untilEncoderCounts(-50, dgtl2);
	untilEncoderCounts(45, dgtl4);
	stoplift();
	SensorValue(dgtl1) = 0;
	lift(-127, -127);
	untilEncoderCounts(0, dgtl2);
	untilEncoderCounts(0, dgtl4);
	stoplift();

}

This code works fine but the one below doesn’t… All that was changed was the negatives in the line marked.


task autonomous()
{
	
	SensorValue(dgtl1) = 1;
	wait1Msec(1000);
	lift(127, 100);
	untilEncoderCounts(-40, dgtl2);
	untilEncoderCounts(35, dgtl4);
	stoplift();
	drive(63, 63, 63, 63);
	wait1Msec(1200);
	stopdrive();
	lift(-127, -127);		//This is the line thats causing problems
	untilEncoderCounts(-50, dgtl2);
	untilEncoderCounts(45, dgtl4);
	stoplift();
	SensorValue(dgtl1) = 0;
	lift(-127, -127);
	untilEncoderCounts(0, dgtl2);
	untilEncoderCounts(0, dgtl4);
	stoplift();

}

Once it gets to the line that’s causing problems, the program just stops altogether. It won’t continue anything after that… I lifts, drives forward, and then the program ends.

I’m wondering what happens if the reading on your encoder counts is going by so fast the code doesn’t update the count fast enough and therefore doesn’t “see” -50 but only sees -55… -56… or whatever. Is that possible?



        untilEncoderCounts(-50, dgtl2);
	untilEncoderCounts(45, dgtl4);

My kids recently had something like that happen. After hours of trying everything they could think of, they finally shut down their program, restarted their computer, and reloaded the program, re-uploaded their code, and from then on it worked fine.

That could be a possibility… If so I’m not quite sure how I would fix it. Any Ideas?

We had this issue eariler before. The way we resolved it was by using a preset of 1000 instead of 0. That way you are always using positive numbers. lifting up and down.

I bet your lift function needs absolute value.

Imagine this
while(goal-encoder>20)
This means while I am more than 20 ticks away keep trying to get closer.
now if the goal is below the encoder goal-encoder will be negative and never above 20.

So normally it needs to be written as
while(abs(goal-encoder)>20)

I wrote this before I realized you were using the easyC fancy blocks but it seemed to be worth keeping because people run into this issue a lot.

Is that what he’s using? Heck, I thought he was using RobotC and those were his defined functions or something. Oops. :o

We are 100% using RobotC lol

Lol woops. When you didn’t include the function definitions I doubted my original idea.

In that case its probably what I said. I remember reading about the fancy new easyc blocks that are named very similarly to your function.

The general case functions you wrote really should be less general case. Its not the end of the world to have a lift to height function. This also means your code is easily adaptable to add a P controller later on.

Can you post the entirety of your custom lift function (including parameter definitions) for us to debug? We’ll need this code in order to see what could be causing the issue in the code.

Thanks in advance!

This seems to me to be the most logical solution. I add it into all my programs from the start so I don’t to worry about it at all.

I just realized that your code is using these

http://cdn.robotc.net/pdfs/natural-language/Natural_Language_Cortex.pdf

I thought the wait function was yours. I haven’t used those much.

I would also recommend using the sensor names rather than the sensor ports when calling the untilencoder function. This will allow more readable code which is not only good for us but actually good for you debugging as well.