RobotC Encoder Problem

I hate constantly pestering everyone with my coding issues, but I am stumped!

I installed a set of quadrature encoders and was trying a simple routine to play with them but I keep getting an issue for the left encoder. I have moved it from digital ports 2-3 to 3-4, 4-5, 6-7, 7-8 and nothing helps. I have attached a picture of the error I am getting on my computer screen, as well as the code.

I get this error regardless of the value being 1000 or -1000.

What am I missing here???

http://sbdrobotics.com/wp-content/uploads/2013/02/photo1.jpg


#pragma config(Sensor, dgtl1,  RightEncoder,   sensorQuadEncoder)
#pragma config(Sensor, dgtl7,  LeftEncoder,    sensorQuadEncoder)
#pragma config(Motor,  port2,           rightMotor,    tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port4,           armMotorlleft, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port5,           armMotorright, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port6,           intakeMotor,   tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port7,           leftMotor,     tmotorServoContinuousRotation, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{

SensorValue[RightEncoder] = 0;
SensorValue[LeftEncoder] = 0;
if(nMotorEncoder(RightEncoder) <1000)
{
	motor[rightMotor] = 100;	
}
if(nMotorEncoder(RightEncoder) == 1000)
{
	motor[rightMotor] = 0;
}
if(nMotorEncoder(LeftEncoder) <-1000)
{
	motor[leftMotor] = 100;
}
if(nMotorEncoder(LeftEncoder) == -1000)
{
	motor[leftMotor] = 0;
}

Use “SensorValue[RightEncoder]” for a quadrature encoder, and “nMotorEncoder(RightEncoder)” if you’re using IMEs.

I’ve never seen anybody use “nMotorEncoder” before. Try “SensorValue[leftEncoder]” instead.
EDIT: Darn RoboDesigners beat me to it

This is what I currently have and it doesn’t work. At this point I’m exhausted and not in the frame of mind to mess with it until later. I don’t see what’s wrong!

I just started using RobotC last month so there is still a steep learning curve since I don’t know C or C++ either…

#pragma config(Sensor, dgtl1,  RightEncoder,   sensorQuadEncoder)
#pragma config(Sensor, dgtl7,  LeftEncoder,    sensorQuadEncoder)
#pragma config(Motor,  port2,           rightMotor,    tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port4,           armMotorlleft, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port5,           armMotorright, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port6,           intakeMotor,   tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port7,           leftMotor,     tmotorServoContinuousRotation, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//




task main()
{

SensorValue[RightEncoder] = 0;
SensorValue[LeftEncoder] = 0;
if(SensorValue[RightEncoder] <1000)
{
	motor[rightMotor] = 100;	
}
if(SensorValue[RightEncoder] == 1000)
{
	motor[rightMotor] = 0;
}
if(SensorValue[LeftEncoder] <-1000)
{
	motor[leftMotor] = 100;
}
if(SensorValue[LeftEncoder] == -1000)
{
	motor[leftMotor] = 0;
}
}

Ok, I did a rectal-cranial extraction and found the video on programming encoders. I think I can dig my way out of this one. Thanks for the help!

Just in case anyone else stumbles upon this thread in the future:

The symptom you’re probably experiencing is that the motor turns on for a very sort time (probably not noticeable), and the program terminates.

The solution is to use a loop of some kind:

#pragma config(Sensor, dgtl1,  RightEncoder,   sensorQuadEncoder)
#pragma config(Sensor, dgtl7,  LeftEncoder,    sensorQuadEncoder)
#pragma config(Motor,  port2,           rightMotor,    tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port4,           armMotorlleft, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port5,           armMotorright, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port6,           intakeMotor,   tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port7,           leftMotor,     tmotorServoContinuousRotation, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//




task main()
{

  SensorValue[RightEncoder] = 0;
  SensorValue[LeftEncoder] = 0;
  
  //Run until the target condition is attained
  while(SensorValue[RightEncoder] < 1000 || SensorValue[LeftEncoder] > -1000) {
    if(SensorValue[RightEncoder] < 1000) //If the right wheel hasn't gone far enough...
    {
      motor[rightMotor] = 100;	
    }
    if(SensorValue[RightEncoder] >= 1000) //If we've reached (or passed) our goal
    {
      motor[rightMotor] = 0;
    }
    if(SensorValue[LeftEncoder] > -1000) //If we haven't gone far enough (note the greater-than, not less-than symbol; this is because of the negative numbers)
    {
      motor[leftMotor] = 100;
    }
    if(SensorValue[LeftEncoder] <= -1000) //If we've reached or passed our goal
    {
      motor[leftMotor] = 0;
    }
  }
}

You get the exception because nMotorEncoder needs the motor port not the encoder port. In your case this means you need to use.

nMotorEncoder leftMotor ];

There are two advantages to nMotorEncoder compared to using SensorValue.

  1. Positive command value will always return incrementing encoder values. ie. the motor reverse flag is used to flip the value of nMotorEncoder if it is set.
  2. nMotorEncoder returns a long, SensorValue returns a short. SensorValue will cause problems for encoder counts about 32767.