View unanswered posts | View active topics It is currently Mon Sep 01, 2014 5:40 pm






Reply to topic  [ 35 posts ]  Go to page Previous  1, 2, 3  Next
nMotorEncoderTarget[] not working.. 
Author Message
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3209
Location: Rotterdam, The Netherlands
Post Re: nMotorEncoderTarget[] not working..
It can happen when the motor position is ever so slightly before the intended target. I am not sure there's a real fix for it other than implementing some code yourself that is a bit more lenient wrt intended motor target, ie stop the motor ithin 1-2% of the intended target. I would submit a ticket with some example code to support@robotc.net just the same.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Feb 14, 2012 3:27 am
Profile WWW
Rookie

Joined: Sat Jan 14, 2012 6:54 pm
Posts: 2
Post Re: nMotorEncoderTarget[] not working..
We have the same problem with Tetrix DC motors. nMotorEncoderTarget[] / runStateIdle not stopping the motors. They just keep on turning until the encoders read about 48,000+-.

Code:
#pragma config(Hubs,  S1, HTMotor,  HTServo,  none,     none)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C1_1,     motorL,        tmotorTetrix, PIDControl, reversed, encoder)
#pragma config(Motor,  mtr_S1_C1_2,     motorR,        tmotorTetrix, PIDControl, encoder)
#pragma config(Servo,  srvo_S1_C2_1,    servo1,               tServoStandard)
#pragma config(Servo,  srvo_S1_C2_2,    CamPitch,             tServoStandard)
#pragma config(Servo,  srvo_S1_C2_3,    servo3,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_5,    servo5,               tServoNone)
#pragma config(Servo,  srvo_S1_C2_6,    servo6,               tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

// Demo Robot Code

task main()
{
// using Tetrix Encoders on differential drive bot:
nMotorEncoder[motorL] = 0;
nMotorEncoder[motorR] = 0;

nMotorEncoderTarget[motorL] = 1440;  // 1440 = one revolution
nMotorEncoderTarget[motorR] = 1440;

motor[motorL] = 50;
motor[motorR] = 50;

while (nMotorRunState[motorL] != runStateIdle && nMotorRunState[motorR] != runStateIdle) // wait for both motors to reach idle
   { // idle loop, except to display encoder values
      eraseDisplay();
      nxtDisplayString(2,"E L = %d", nMotorEncoder[motorL]);
      nxtDisplayString(4,"E R = %d", nMotorEncoder[motorR]);
      wait1Msec(100);
   }
   
motor[motorL] = 0;  // should be off anyway after using nMotorEncoderTarget
motor[motorR] = 0;

PlayImmediateTone(500,100);  // freq, duration(10ths)

wait1Msec(2000); // used to read final encoder values on screen before ending program
}


Since we are reading the encoder values right on the NXT screen, everything is wired up correctly, and the motors sail right through our target 1440.

I noticed the latest posts on this are over a year old. Did I miss the fix? (I have the latest RobotC version, downloaded this morning)


Wed Oct 03, 2012 5:39 pm
Profile
Rookie

Joined: Sat Jan 14, 2012 6:54 pm
Posts: 2
Post Re: nMotorEncoderTarget[] not working..
Is this still true...as quoted 2 years ago???...

==================================

You should always add a small delay between resetting the encoders and executing a new motor command. I usually add something like 50-100ms.

- Xander[/quote]

=================================


Wed Oct 03, 2012 6:11 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3209
Location: Rotterdam, The Netherlands
Post Re: nMotorEncoderTarget[] not working..
It may not need to be 50ms, but I am pretty sure it still stands true. It's just how the system works. Resetting the encoders requires a few I2C calls to the controller. I am sure there are few internal things that need to be dealt with, too.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Thu Oct 04, 2012 12:34 am
Profile WWW
Rookie
User avatar

Joined: Sat Sep 03, 2011 10:03 am
Posts: 32
Post Re: nMotorEncoderTarget[] not working..
Xander and others: I am also having a problem with the Tetrix motors not stopping using nMotorEncoderTarget[]. The motor continues to run until a timeout I have in my software turns the motor power off.

I added counters to keep track of the motor run state and get many hold and running state counts. No Idle, RampUp or RampDn counts. Even the NXT Devices display shows the state to be running when the motors are all stopped. It is not a matter of not reaching the target, that was last years problem. :D

I can post the code if desired but even the reduced version is a bit verbose. This all worked with 3.08 but not with 3.51 with the released third party driver package. Below is a snippet of the failing loop and the associated Pragma.

On another subject: Did I read on this thread that if you use a negative target, that the PID is not activated?


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

Code Snippet:
nMotorEncoder[Shoulder] = 0; //* Start encoder at Zero *//
nMotorEncoderTarget[Shoulder] = ShoulderTravelAmount; //* Set target for encoder *//
wait10Msec(30); //* Wait a bit before starting motor *//
Hold = 0;
Running = 0;
MtrIdle = 0;
RampUp = 0;
RampDn = 0;
motor[Shoulder] = ShoulderPower; //* Start motor *//
wait10Msec(30); //* Let motor get started *//
ClearTimer(T3); //* Get timer ready to get out if the Shoulder hangs. *//
while(time10[T3] < timelimit)
{
Timer = time10[T3];
if (nMotorRunState[Shoulder] == runStateHoldPosition) Hold +=1;
if (nMotorRunState[Shoulder] == runStateRampUp) RampUp +=1;
if (nMotorRunState[Shoulder] == runStateRampDown) RampDn +=1;
if (nMotorRunState[Shoulder] == runStateRunning) Running +=1;
if(nMotorRunState[Shoulder] == runStateIdle)
{
motor[Shoulder]=0;
MtrIdle +=1;
wait10Msec(30); //* Let motor settle *//
ShoulderPosition = DesiredShoulder; //* We should be where desired *//
return(0); //* Return to caller *//
}
}
motor[Shoulder] = 0; //* Stop motor *//
wait10Msec(50); //* Wait for motor to stop *//


Wed Oct 17, 2012 11:21 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: nMotorEncoderTarget[] not working..
I would avoid using "if (nMotorRunState[Shoulder] == runStateIdle)". Try the following instead:
Code:
if (abs(ShoulderTravelAmount- nMotorEncoder[Shoulder]) <= ShoulderTolerance)


Wed Oct 17, 2012 12:03 pm
Profile
Rookie
User avatar

Joined: Sat Sep 03, 2011 10:03 am
Posts: 32
Post Re: nMotorEncoderTarget[] not working..
I just got a message from RobotC Support regarding my ticket #247104 that they were able to reproduce the problem and will fix it in 3.52.

No additional information so I do not know what the problem is/was. Perhaps someone can provide additional info for the forum readers.

Wouldn't it be nice if this has been the major thorn that a lot of people have been having with nMotorEncoderTarget[]. :D :D


Wed Oct 17, 2012 12:08 pm
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 602
Post Re: nMotorEncoderTarget[] not working..
We just stumbled upon this in our test cases - we've been so focused with Compiler issues that this one seemed to get in under the radar.

The issue is probably related to the MATRIX controller integration - we had to go back and modify all of the TETRIX commands to work with MATRIX as well - this is probably when this error was introduced. I haven't had a chance to dig into it to say exactly what the issue is, however.

We should have something available in the next day or so for our internal testers - if you're interested in being apart of this test group, send me an e-mail to tfriez [at] robotc (dot) net and I'll add your e-mail to the list.

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Wed Oct 17, 2012 12:15 pm
Profile
Rookie
User avatar

Joined: Sat Sep 03, 2011 10:03 am
Posts: 32
Post Re: nMotorEncoderTarget[] not working..
MHTS wrote:
I would avoid using "if (nMotorRunState[Shoulder] == runStateIdle)". Try the following instead:
Code:
if (abs(ShoulderTravelAmount- nMotorEncoder[Shoulder]) <= ShoulderTolerance)



The problem with this solution is that the motor always over or undershoots the desired position. The time it takes to read and test the encoder value allows the motor to go way past the intended position.

Did I read on this forum that a negative target prevents the built-in PID from working? That PID prevented last years robot from getting a motor to the desired position by reducing power to the point it would not move. Until those controllers are really programmable as far as the PID is concerned, I think one may have to do their own version of slowing the motor and testing the encoder. "Poor man's working PID"


Wed Oct 17, 2012 12:53 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: nMotorEncoderTarget[] not working..
Mentor3923 wrote:
The problem with this solution is that the motor always over or undershoots the desired position. The time it takes to read and test the encoder value allows the motor to go way past the intended position.

Did I read on this forum that a negative target prevents the built-in PID from working? That PID prevented last years robot from getting a motor to the desired position by reducing power to the point it would not move. Until those controllers are really programmable as far as the PID is concerned, I think one may have to do their own version of slowing the motor and testing the encoder. "Poor man's working PID"

I don't know what the RobotC bug was but in general, what you said is exactly the problem. Even if there is no bug in RobotC, in general, a Proportional only controller will have a "steady state error" so if you are testing for exact target distance, you will never get there. That's why we gave it a tolerance to account for the steady state error. It may help if we can tune the PID constants and be able to add the Integral and Differential terms of the PID control, but those are not accessible with the built-in PID control. That's why we implemented our own PID controller in our FTC library.


Thu Oct 18, 2012 2:15 am
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 602
Post Re: nMotorEncoderTarget[] not working..
For the next release (and current private BETA) we have switched ROBOTC's implementation from running our own PID algorithm to using the integrated one in the HiTechnic Controller.

There was an issue when implementing the functionality for Matrix that ended up breaking ROBOTC's implementation. We have resolved this issue for our private BETA (if you wish to try it out, send me an e-mail).

The program I'm using to test is as follows. You can modify the speed, distance and also which port it runs on. I've confirmed this code works with both PID enabled and disabled.

Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTMotor,  HTMotor)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorTetrix, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorTetrix, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C2_1,     motorF,        tmotorTetrix, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C2_2,     motorG,        tmotorTetrix, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C3_1,     motorH,        tmotorTetrix, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C3_2,     motorI,        tmotorTetrix, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C4_1,     motorJ,        tmotorTetrix, openLoop, encoder)
#pragma config(Motor,  mtr_S1_C4_2,     motorK,        tmotorTetrix, openLoop, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
   tMotor testArray[8] = {motorD, motorE, motorF, motorG, motorH, motorI, motorJ, motorK};

   int speed = 50;
   int distance = 2880;

   for(int i = 0; i < 8; i++)
   {
      nMotorEncoderTarget[testArray[i]] = distance;
      motor[testArray[i]] = speed;

      while (nMotorRunState[testArray[i]] != runStateIdle)
      {
         nxtDisplayTextLine(1,"Motor #: %d", i);

         switch(nMotorRunState[testArray[i]])
         {
            case runStateRunning: nxtDisplayTextLine(3,"Status: Running"); break;
            case runStateHoldPosition: nxtDisplayTextLine(3,"Status: HoldPos"); break;
            case runStateIdle: nxtDisplayTextLine(3,"Status: Idle"); break;
            default: nxtDisplayTextLine(3,"Status: Unknown"); break;
         }
      }
      wait1Msec(1000);
   }
}

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Thu Oct 25, 2012 12:33 pm
Profile
Rookie
User avatar

Joined: Wed Dec 01, 2010 5:15 pm
Posts: 30
Post Re: nMotorEncoderTarget[] not working..
When will that version be released?


Thu Oct 25, 2012 7:12 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 566
Post Re: nMotorEncoderTarget[] not working..
We have a tentative release date set for Friday, November 2nd, but that is subject to change depending what the beta testing reveals. If you absolutely need the patch sooner, you can sign up for the beta by emailing tfriez@robotc.net. Please note, however, that it will be a beta build and as such, may be prone to bugs and issues (which is why we run a beta period; to get all of said bugs worked out before the release).

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Fri Oct 26, 2012 9:28 am
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 602
Post Re: nMotorEncoderTarget[] not working..
This is now fixed in 3.54.

Thanks for all of the help with this!

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Mon Nov 05, 2012 9:39 pm
Profile
Rookie

Joined: Mon Nov 29, 2010 10:56 am
Posts: 4
Post Re: nMotorEncoderTarget[] not working..
So now that this is working, how do you use nMotorEncoderTarget to move a TETRIX motor to a position and hold it there against significant deviating forces using PID control? The target position would be changing over time based on joystick input. This is for an arm joint.

We wish to use the built-in hitechnic motor controller's PID capability. We tried rolling our own PID code and haven't been able to get it tuned right.


Fri Feb 08, 2013 1:30 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 35 posts ]  Go to page Previous  1, 2, 3  Next

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.