How to use IMEs in robotc?

My team this year has decided to use imes on the drivetrain to have a reliable autonmous. I have been looking on this video I have put the code exactly the same in my program but, when I run it it never stops the motors. We could just use shaft encoders but, those can’t do pid adjustments. So,if anyone knows how to get this program to work that would be amazing!

It sounds like maybe you haven’t connected the IEMs properly to your robot. Here are a few pointers on that:

  1. Make sure that each motor has the special black and white encoder gear on the back part where you’ve attached the actual IEM itself.
  2. Make sure that you’ve plugged in the I2C wires the correct way. The light on the IEM should turn on
  3. Make sure that the IEMs are flashing a green light. If they’re all working and wired correctly in the chain (and configured in your program), you’ll seen one green flash every second or so on all IEMs except the last one, and two quick green flashes in a row every second or so on the last one.
  4. Sometimes the IEMs just don’t work. As a last resort, you can try swapping the IEM for a new one if you have a spare. I’ve noticed that sometimes older IEMs (that typically don’t work) have some kind of white build-up in them (other people on the forum have mentioned this before, so you could search for it if you’re curious).
  5. There are some good tips in this thread

Also, you should be able to use a quad encoder (though I’ve never tested that) for the ROBOTC built-in PID. Just select a digital port next to Encoder Port in the Motors and Sensors Setup. You can definitely use a quad encoder for PID that you’ve written yourself.

Lastly, open up the Sensors debug window and make sure that the encoder value counts up or down when you rotate the motor manually. If not, then no code based on that motor’s encoder value will work properly.

All the of the encoders are working and the left is giving a positive value. But this shouldn’t matter because in the video the right encoder is opposite of the left just like mine. The built in pid has never worked for so i am done trying that. Unless you have a way for it to not interrupt the joystick control.

That video uses very simplistic programming, as the author is not much of a programmer (wink). It is not using PID control with the IME’s, so the code might not work if you have checked those boxes.

Looking in the robotC sample programs (File > Open Sample Program > Integrated Encoders > ) there are some examples of using PID control. You are correct that PID and joystick control do not work together. If you want PID in auton, you will need reconfigure the motors at the top of your user control to exit PID control.

First thank you for making those videos they’re the only ones that have helped us! I am not meaning exactly a pid loop just automated straightening, so that we go straight every time. I will look at those sample codes, but your code should work. I’m reading values from the imes but it seems as if the program isn’t getting the value.

You are welcome. Glad people are finding the videos useful. @evan10s listed some things to rule out hardware issues. Other possibilities:
-If those are all correct, it might be you have the wrong IME listed as I2C_1… its the one connected to the cortex.
-If you don’t take abs(sensorValue) then negative values would make the while statements always true and the motor would run forever.

Here is that function for you to confirm against yours:

// function to run autoDrive for specified distance in units defined by wheelDiameter then stop the drive motors
// for wheeldiameter of 4", dist must be in inches.  for wheeldiameter of 10.16cm, dist must be in centimeters.
// +speed = forward, -speed = reverse. lower speeds are more accurate. 80 works well.
// distance always positive.
void autoDriveDist(int speed, int dist)
	nMotorEncoder[driveLF] = 0;	// reset the IEM value to 0
	nMotorEncoder[driveRF] = 0;	// reset the IEM value to 0
	int ticks = dist/(wheelDiameter*PI) * eDriveTicks; 	// convert distance into encoder ticks. wheelDiameter and eDriveTicks set in globals

	while (abs(nMotorEncoder[driveLF]) < ticks*.6)	// while driveLF is less than 60% of ticks
		int rDiff = abs(nMotorEncoder[driveLF]) - abs(nMotorEncoder[driveRF]); // check for right encoder difference
		int rMod = sgn(rDiff)*speed*.1; 	// rMod = 10% speed in the direction of rDiff
		motor[driveLF] = speed;	// run motors at speed for first 60% of ticks
		motor[driveLB] = speed;
		motor[driveRF] = speed + rMod;	// rMod is + when right encoder < left, rMod is - when right encoder > left
		motor[driveRB] = speed + rMod;

	while (abs(nMotorEncoder[driveLF]) < ticks)	// while driveLF is less than the ticks
		int rDiff = abs(nMotorEncoder[driveLF]) - abs(nMotorEncoder[driveRF]); // check for right encoder difference
		int rMod = sgn(rDiff)*speed*.1;  // rMod = 10% speed in the direction of rDiff
		motor[driveLF] = speed/3;	// run motors at 1/3 speed for last 40% of ticks
		motor[driveLB] = speed/3;
		motor[driveRF] = speed/3 + rMod;
		motor[driveRB] = speed/3 + rMod;

	autoDriveTime(-speed/2, 50);	// briefly run the drive motors at - 1/2 speed to counter momentum

If, while its running, the local variables show rDiff changing, then the sensors are reporting changing values. You could add a line to save the current sensor value to a local variable in the while loops to monitor what is happening:

int ime_R = abs(nMotorEncoder[driveRF]); // check for right encoder value		
int ime_L = abs(nMotorEncoder[driveLF]); // check for left encoder value

I just went onto robots to check if it is getting the values and it is. But the while loop still doesn’t end. I’m getting a solid green light meaning direction. So I am lost

This program should keep the robot going straight correct?

Yes, the code should speed or slow the right side to keep it equal to left.

Do you have a version of the program to work with shaft encoders?

Just skimmed through the code. If you declare everything correctly in motor sensor setup you should be able to use his code out of the box.

Can you send me a pic of the settings of the motors and sensors? I believe I have it all right.

[quote=“Gameon2546, post:12, topic:36710”]

Can you send me a pic of the settings of the motors and sensors? I believe I have it all right.

Thank you for all your help, this is all I needed to make reliable autonomous! I was calling the name I gave to the 12c sensors tab, which was the problem.