View unanswered posts | View active topics It is currently Wed Aug 05, 2020 4:42 am

Reply to topic  [ 2 posts ] 
IC2 nMotorEncoder Encoder problem 
Author Message

Joined: Wed Oct 20, 2010 12:30 pm
Posts: 4
Post IC2 nMotorEncoder Encoder problem
We are trying to use the new IC2 Encoders on both 393 and 269 motors and we are having problems. On the 269 motors we want to us a auto straightening but one of the encoders reads negative and we can not figure out how to make it positive so we can compare encoders. Our second problem is that we can not get the "ArmEncoder" to count to 1500 and stop. It will keep going. Attached is the code (sorry it is long).

#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, in1, R, sensorLineFollower)
#pragma config(Sensor, in2, L, sensorLineFollower)
#pragma config(Sensor, dgtl12, autobutton, sensorTouch)
#pragma config(Sensor, I2C_1, leftIEM, sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Sensor, I2C_2, rightIEM, sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Sensor, I2C_3, rightarmIEM, sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Sensor, I2C_4, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Motor, port1, Armleft, tmotorVex393, openLoop, reversed)
#pragma config(Motor, port2, Leftfront, tmotorVex269, openLoop, reversed, encoder, encoderPort, I2C_1, 1000)
#pragma config(Motor, port3, Leftrear, tmotorVex269, openLoop, reversed)
#pragma config(Motor, port4, Scoopleft, tmotorVex393, openLoop, reversed)
#pragma config(Motor, port7, Scoopright, tmotorVex393, openLoop, encoder, encoderPort, I2C_4, 1000)
#pragma config(Motor, port8, Rightrear, tmotorVex269, openLoop)
#pragma config(Motor, port9, Rightfront, tmotorVex269, openLoop, encoder, encoderPort, I2C_2, 1000)
#pragma config(Motor, port10, Armright, tmotorVex393, openLoop, reversed, encoder, encoderPort, I2C_3, 1000)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

void forward()
nMotorEncoder[Rightfront] = 0;
nMotorEncoder[Leftfront] = 0;
while(nMotorEncoder[Leftfront] > -700)

motor[Rightfront] = 63;
motor[Rightrear] = 63;
motor[Leftfront] = 63;
motor[Leftrear] = 63;

motor[Rightfront] = 0;
motor[Rightrear] = 0;
motor[Leftfront] = 0;
motor[Leftrear] = 0;


void backwards ()
nMotorEncoder[Rightfront] = 0;
nMotorEncoder[Leftfront] = 0;

while(nMotorEncoder[Leftfront] < 1000)
motor[Rightfront] = -63;
motor[Rightrear] = -63;
motor[Leftfront] = -63;
motor[Leftrear] = -63;
void armup()
nMotorEncoder[Armright] = 0;

while(nMotorEncoder[Armright] < 1)

void clean()
motor[Rightfront] = 0;
motor[Rightrear] = 0;
motor[Leftfront] = 0;
motor[Leftrear] = 0;

task main ()




Wed Jun 05, 2013 2:13 pm
Site Admin
Site Admin
User avatar

Joined: Tue Oct 09, 2012 10:34 am
Posts: 192
Post Re: IC2 nMotorEncoder Encoder problem
Hi A,
1. Setting the motor as reversed won't reverse the encoder value. Since the encoders are turning in opposite directions (even though both sides may be pushing the robot forwards or are moving the arm in the same direction, one's turning clockwise, the other anticlockwise), one of the encoders' values will be negated. If you zero the encoders before you start the move, you can simply compare the value of one encoder to the negated value of the other encoder.

2. Your arm motors are not stopping because your code never tells them to stop. Try adding the following code at the end of your armup() function, after the while loop.


Ryan Cahoon
CMU Robotics Academy
RVW Software Developer

Robot Potato Head; Virtual NXT

Tue Jul 16, 2013 4:43 pm
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.