IME Randomly reading the same value

I posted a couple months ago about this problem. I reposed because I did not know if I would get a reply on that that thread. Randomly the IME will get stuck reading the same value. This makes the robot drive into infinity. I will attach my code to help with finding the problem. The code for the IME is in “Drive” and “Drive_Sideways” functions.
4191 Raptor Robotics IME Reading same value.zip (30.8 KB)

I am curious why you have determined this to be root cause of your problem? I see no debug statements in the code that would reveal the value of the encoders during run time. I haven’t used EasyC with IME’s nor in a long time so maybe they added real time debugging but when I used to work with it I had to print out values to the Terminal or the Graphics display.

In review of your control loop in Drive:

you enter an infinite loop and potentially control 6 motors (2 for the bucket which I don’t see you ever getting position data for) and 4 for the drive. You are collecting position data for 2 motors and averaging them after correcting for direction.

Sample encoder:

        enc_l = GetIntegratedMotorEncoder ( 7 ) ;
        enc_r = GetIntegratedMotorEncoder ( 4 ) ;

Average Encoder:

        enc_all = ((enc_l*direction_multiplier_l) + (enc_r*direction_multiplier_r))/2 ;

your exit condition for the loop is here:

        if ( enc_all >= distance )
        {
              break ;
        }

I would not recommend averaging 2 encoders to be used as a trigger. Generally i control each motor independently and as you have 4 encoders on the 4 drive motors this is pretty straightforward.

I can’t really piece together what might have happened from a code review. But I can think of some scenario’s where this code would drive forever.

How extensively have you tested this code? Does it work for some values of direction and not others? does it work most of the time for all values of direction?

Have you instrumented the code to detect when the encoders stop updating?

Is there some physical problem (loose wire etc.) with the IME / Cortex?

Are the Batteries good on the Cortex? solid connections etc…

When the robot runs infinitely what are the LED s on the handset / cortex doing?

When you say it fails randomly, is it truly unpredictable? Can you provide more information on when it has worked and under what conditions it has failed?

There are so many things that could be wrong, I’d need a much better picture of what’s going on to isolate the problem.

Cheers Kb

As Kevin said, a couple of things would help diagnose the problem.

  1. An explanation of how you have determined the IMEs are returning bad data.
  2. Simplified code that demonstrates the problem.

At first glance I don’t see anything obvious, there are a couple of things that make me ask myself “is that a problem?”, for example, enc_all is of type int whereas enc_l and enc_r are of type long, but this probably works ok.

If the value from both encoders really does just freeze, it’s most likely intermittent wiring or a bug in the EasyC runtime library that we have to find a workaround for.

I programmed the LCD to display the value of “enc_all”. When the drive function is working, the LCD displays the distance the robot has traveled. When it gets stuck in a loop it displays an unchanging value. I will be working on the robot today. I will try to make some simple code that reproduces the problem.

I forgot one thing. When it fails all the IME lights are dim, green and flash really fast.

I have not tried making code to detect when it does it. Good Idea :D!

The wires are all good.

I think it does it more often when the batteries are low.

The lights on the robot and joystick do not change when it happens.

Yes it is random. One time it will fail and the next time every thing will work.

Thanks!