Blog

Using Jaguar Controllers to Drive CIM Motors

John Keogh | May 13, 2014

I couldn't finding an article which contained source and discussion for running a CIM motor from a Jaguar controller using an Arduino, so if you are looking for this information, here it is. The video shows a robot which is built with these components, so if you want to see this is action, it's in the video.

The parts used, which are shown in the video, are: two 560 Ohm resistors, two Jaguar controllers, an arduino Uno, a 12 volt lead-acid battery, two CIM motors from VEX Robotics. Do not use this as is, since there needs to be a gear box to gear it down at least 10X. since it is way to fast as shown.

Code

Below is a sketch that you can use to control the CIM motors.

Servo leftJagController; Servo rightJagController; int leftJagPin = 10; int rightJagPin = 11; void setup() { leftJagController.attach(leftJagPin); rightJagController.attach(rightJagPin); Serial.begin(57600); } // the loop routine runs over and over again forever: void loop() { while (Serial.available()) { delay(3); //delay to allow buffer to fill if (Serial.available() >0) { char c = Serial.read(); //gets one byte from //serial buffer //IMPORTANT: commands are space delimited, there //are no \r\n in the stream from the laptop (makes //it easier to work with manually from the serial //monitor if(c==' '){ commandString[currentChar]='\0'; processCommand(commandString); currentChar =0; } else{ commandString[currentChar++]=c; } } } } //assumes command over serial port like: //l:150 //r:250 //the range is 100 to 300, subtract 200 to get -100 to //100, since we don't want to deal with the negative sign //and want 3 characters, so range is adjusted to 100 to //300 void ProcessCommand (char *command){ if(command[0]=='l'){//left int velocity = GetVelocity(command); velocity -=200; leftJagController.writeMicroseconds(map(velocity, -100, 100, 670, 2330)); } else if(command[1]=='r'){//right int velocity = GetVelocity(command); velocity -=200; rightJagController.writeMicroseconds(map(velocity, -100, 100, 670, 2330)); } } int GetVelocity(char *command){ char velocity [4]; velocity[0]=command[2]; velocity[1]=command[3]; velocity[2]=command[4]; velocity[3]='\0'; return atoi(velocity); }

Cautions and Comments

The primary issue that you will run into is sending the commands over the serial port. The easiest way is to inject them manually using the serial monitor built into the Arduino IDE. Alternately, the .Net SerialPort object for Windows or the ORSSerialPortManager library for the Mac OS are pretty easy to use and you can then control the motors from a desktop program.

The primary caution is that the motors turn very rapidly, so they need to be geared, otherwise the robot will take off very rapidly. The robot is the video uses PWM from 1% -10% duty cycle, and is still hard to control. If you gear the motors down about 20X the speed should be about right.

Eyesbot Company

Computer vision

Artificial intelligence

Effecting the physical world