View unanswered posts | View active topics It is currently Thu Jul 31, 2014 5:29 am






Reply to topic  [ 6 posts ] 
One Encoder Works; The Other Ones Does Not 
Author Message
Rookie

Joined: Wed Jan 01, 2014 11:17 am
Posts: 2
Post One Encoder Works; The Other Ones Does Not
Hi Everyone --- Rookie coach is stumped... :(

We're trying to use our encoders. motorD seems to be controlled but motorE acts as if it is not being controlled. The link below is exactly our problem:
viewtop...=2774&start=15

It was fixed in ROBOTC 3.54. We are running ROBOTC 3.62

Using the code below, MotorD turns 1/4 revolution at what appears to be 50% power. MotorD seems to behave as expected if you change its values for nMotorEncoderTarget[motorD] or motor[motorD]. On the other hand, MotorE ALWAYS runs at 100% power and ALWAYS turns several full revolutions before it stops when it finally reaches the set target value (negative) as seen in the NXT Device Control Display debugger window. If you change motorE's power setting it is ignored.

Both encoder wires are plugged into the motor controller so the orange wire faces the motor controller's lettering and are plugged into the motors so orange is left-most when looking at and reading the label on the motor. We have tried swapping motor controllers, the encoder cables, and we've hooked up motorD as mtr_S1_C1_2 and motorE as mtr_S1_C1_1 all with the same result. It also does not matter which motor is reversed in the pragma. I've opened up the encoder on motorE and it seems to be installed correctly. We have not swapped the encoders themselves because that would entail pulling off the encoder wheels, which I'm not ready to do.

We are using this power-up sequence:
1. Power up 12v to motor controller
2. Power up NXT
3. Download and run program

Any suggestions most appreciated!


Code:
#pragma config(Hubs,  S1, HTMotor,  none,     none,     none)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorTetrix, PIDControl, encoder)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorTetrix, PIDControl, reversed, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
  nMotorEncoder[motorD] = 0;
  nMotorEncoder[motorE] = 0;
  nMotorEncoderTarget[motorD] = 720;   //Gearing ratio is 1:2 so one revolution is 2880 encoder ticks
  nMotorEncoderTarget[motorE] = 720;    //@720 ticks both wheels should turn 1/4 revolution
  motor[motorD] = 50;
  motor[motorE] = 50;
  wait1Msec(100);

  while (nMotorRunState[motorE] != runStateIdle || nMotorRunState[motorD] != runStateIdle)
  {
  }
 
  motor[motorD] = 0;
  motor[motorE] = 0;
  wait1Msec(3000);
}


Wed Jan 01, 2014 11:31 am
Profile
Rookie
User avatar

Joined: Wed Jan 09, 2013 11:48 pm
Posts: 35
Location: Saint Paul, MN
Post Re: One Encoder Works; The Other Ones Does Not
I haven't worked with encoders much but you might want to consider this code in the RobotC help section, it seems to achieve something similar to what you want but in a different fashion.

Code:
nMotorEncoder[motorB] = 0;          // reset the Motor Encoder of Motor B
while(nMotorEncoder[motorB] < 360)  // while the Motor Encoder of Motor B has not yet reached 360 counts:
{
  motor[motorB] = 75;                 // motor B is given a power level of 75
  motor[motorC] = 75;                 // motor C is given a power level of 75
}
motor[motorB] = 0;                  // motor B is given a power level of 0 (stop)
motor[motorC] = 0;                  // motor C is given a power level of 0 (stop)


Maybe that will fix something for you.

_________________
Head Programmer FTC Team 6699, Tempest

Code:
<Life>
   Fun
</Life>


Wed Jan 01, 2014 10:27 pm
Profile WWW
Rookie
User avatar

Joined: Wed Jan 09, 2013 11:48 pm
Posts: 35
Location: Saint Paul, MN
Post Re: One Encoder Works; The Other Ones Does Not
But of course for your case you might want something more like this:

Code:
#pragma config(Hubs,  S1, HTMotor,  none,     none,     none)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorTetrix, PIDControl, encoder)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorTetrix, PIDControl, reversed, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main(){
nMotorEncoder[motorD] = 0;          // reset the Motor Encoder of Motor D
nMotorEncoder[motorE] = 0;         // reset the Motor Encoder of Motor E

while(nMotorEncoder[motorD] < 720)  // while the Motor Encoder of Motor D has not yet reached 720 counts:
{
  motor[motorD] = 50;                 // motor D is given a power level of 50
  motor[motorE] = 50;                 // motor E is given a power level of 50
}

motor[motorD] = 0;                  // motor D is given a power level of 0 (stop)
motor[motorE] = 0;                  // motor E is given a power level of 0 (stop)
}


But again, I haven't worked with encoders much so this could very well be wrong, but worth a try possibly :D

_________________
Head Programmer FTC Team 6699, Tempest

Code:
<Life>
   Fun
</Life>


Wed Jan 01, 2014 10:36 pm
Profile WWW
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: One Encoder Works; The Other Ones Does Not
Try adding some debug statements and see what you get.
Code:
#pragma config(Hubs,  S1, HTMotor,  none,     none,     none)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorTetrix, PIDControl, encoder)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorTetrix, PIDControl, reversed, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
  StopTask(displayDiagnostics);
  eraseDisplay();
  nMotorEncoder[motorD] = 0;
  nMotorEncoder[motorE] = 0;
  nMotorEncoderTarget[motorD] = 720;   //Gearing ratio is 1:2 so one revolution is 2880 encoder ticks
  nMotorEncoderTarget[motorE] = 720;    //@720 ticks both wheels should turn 1/4 revolution
  motor[motorD] = 50;
  motor[motorE] = 50;
  wait1Msec(100);

  while (nMotorRunState[motorE] != runStateIdle || nMotorRunState[motorD] != runStateIdle)
  {
    nxtDisplayTextLine(0, "LEnc=%d", nMotorEncoder[motorD]);
    nxtDisplayTextLine(1, "REnc=%d", nMotorEncoder[motorE]);
  }
 
  motor[motorD] = 0;
  motor[motorE] = 0;
  wait1Msec(10000);
}


Wed Jan 01, 2014 11:25 pm
Profile
Rookie

Joined: Wed Jan 01, 2014 11:17 am
Posts: 2
Post Re: One Encoder Works; The Other Ones Does Not
The problem with the examples is that if motorD is working correctly on PID control and motorE is not responding to PID control the two motors run badly out of synch.

The other ---possibly unrelated but don't know --- problem seems to be the encoder values for motorE are incrementing approximately 80x slower than that for motorD. This seems to happen regardless of loop setting.

The only combination that gives me anything that works is running both motors open loop and look only at motorD 's encoder. Through trial and error I found a "multiplier" that when applied to motorE's speed setting it matches motorD pretty well over several feet. It's not an Ideal solution but it works for our limited use and we have to move on.

Very frustrating to spend all this time on something and not be able to make it work or even understand why it's happening..

I will add diagnostics and see what I get. Will the ones suggested give any additional information than to that provided on the NXT Devices debugger window? MotorE encoder is incrementing much slower (and incorrectly) compared to motorD. When under PID control, it also runs at 100% regardless of the speed setting. In summary when motorE is set to PID control it acts as if it is not being controlled at all.


Wed Jan 01, 2014 11:37 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: One Encoder Works; The Other Ones Does Not
It sounds like you may have a defective encoder. Try the following code. It doesn't run the motors but just monitors the encoder readings. Just run the program and manually turn the wheels 1 revolution and see what the readings are.
Code:
task main()
{
    StopTask(displayDiagnostics);
    eraseDisplay();
    nMotorEncoder[motorD] = 0;
    nMotorEncoder[motorE] = 0;
    while (true)
    {
        nxtDisplayTextLine(0, "DEnc=%d", nMotorEncoder[motorD]);
        nxtDisplayTextLine(1, "EEnc=%d". nMotorEncoder[motorE]);
        wait1Msec(100);
    }
}


Thu Jan 02, 2014 4:30 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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.