ROBOTC.net forumshttp://www.robotc.net/forums/ When nEncoderTarget are reset ?http://www.robotc.net/forums/viewtopic.php?f=1&t=4389 Page 1 of 1

Author:  NeXT-Generation [ Sun Mar 25, 2012 5:16 pm ]
Post subject:  Re: When nEncoderTarget are reset ?

miki wrote:
Hello,

RobotC firmware enters a motor in "active PID regulation mode" when both nEncoderTarget value is set and motor power is set.
RobotC firmware exits a motor of "active PID regulation mode" when nEncoderTarget value is reached.

1. Does RobotC firmware exits a motor of "active PID regulation mode" if motor power is changed ? (ie to go slower)
 Code:nMotorEncoder[motorB] = 0;                // Reset the Motor Encoder of Motor B.nMotorEncoderTarget[motorB] = 360;        // Set the  target for Motor Encoder of Motor B to 360.motor[motorB] = 75;                       // Motor B is run at a power level of 75.wait1Msec(1);motor[motorB] = 50;;                       // Motor B is run at a power level of 50. DOES THE POWER CHANGE MODIFY FIRMWARE REGULATION ???while(nMotorRunState[motorB] != runStateIdle);  motor[motorB] = 0;                       // Motor B is stopped at a power level of 0.
2. Does RobotC firmware exits a motor of "active PID regulation mode" if motor power is stopped the restarted ?
 Code:nMotorEncoder[motorB] = 0;                // Reset the Motor Encoder of Motor B.nMotorEncoderTarget[motorB] = 360;        // Set the  target for Motor Encoder of Motor B to 360.motor[motorB] = 75;                       // Motor B is run at a power level of 75.wait1Msec(1);motor[motorB] = 0;                       // Motor B is run at a power level of 0. DOES THE MOTOR STOP CANCEL µTHE PREVIOUS GOAL (REACH 360) ???wait1Msec(1);motor[motorB] = 75;                       // Motor B is run at a power level of 75. DOES THE FIRMWARE MAINTAIN ITS PREVIOUS GOAL (REACH 360) ???while(nMotorRunState[motorB] != runStateIdle);  motor[motorB] = 0;                       // Motor B is stopped at a power level of 0.
3. What are all conditions possible to cancel the nEncoderTarget ( except to reach it )
4. Is there a safe way to abort a nEncoderTarget while motor is turning and target is not reached ?.

Miki.

I think that your first two statements are wrong. It's my understanding that PID is on only when you've set it to be on, and off when you've set it to be off. But, I might be wrong.

My answers to your questions (again, these are just my answers, take them as you will. ):

1. If by regulation you mean the PID, then no. The PID just tries to keep the motor going at the speed you set.
2. It doesn't cancel the target. That code is fine. (as far as I know)
3. None, I think (other than writing a new target).
4. I'm not exactly sure what you mean. Could you possibly explain better?

Anyway, these are correct as far as I know. Do they satisfy?

Author:  NeXT-Generation [ Mon Mar 26, 2012 7:09 pm ]
Post subject:  Re: When nEncoderTarget are reset ?

 miki wrote:I set the motor to turn until an encoder target is reached AND while a Contact Sensor is not pressed.A contact occurs on sensor (the robot front bumper) and I stop the motor. Internally, the firmware keeps the encoder target set.Then I want to 'push' the obstacle for 5 secondes. So I set the motor to turn during 5 seconds. But if encoder target is reached before the 5 seconds the firmware will stop motor.My questions are related to my project (see my signature) where I created a small simulation of sensors and motors in order to validate my code first in PC-emulator then in real world. Understanding internal firmware behavior will help me to get an accurate motor simulation.Thank for your help.

Ah, okay. To remove the target, simply set the target to "0". That means that you get full control of the motor back.

Here's an example:

 Code:nMotorEncoderTarget[motorA] = 360;motor[motorA] = 100;while(nMotorRunState[motorA] != runStateIdle && SensorValue(touch) == 0);motor[motorA] = 0;if(SensorValue(touch) == 1){  nMotorEncoderTarget[motorA] = 0;  //Resets the encoder so that there is no target.  wait1Msec(5000);  motor[motorA] = 0;}

Author:  NeXT-Generation [ Wed Mar 28, 2012 11:24 am ]
Post subject:  Re: When nEncoderTarget are reset ?

miki wrote:
D'oh!
And now I have the answer it's simple to read deeply the doc!!
 doc wrote:A target value of 0 (zero) means run forever.
Focused on code exemples I didn't pay attention to the text over them