ROBOTC.net forums
http://www.robotc.net/forums/

Matrix motors & nMotorEncoderTarget
http://www.robotc.net/forums/viewtopic.php?f=52&t=7824
Page 1 of 1

Author:  Rotas [ Thu Jan 30, 2014 4:26 am ]
Post subject:  Matrix motors & nMotorEncoderTarget

Hi

We are having no end of trouble with our Matrix motors in RobotC. Has anyone been able to get them working at all?
Our test code looks like this
Code:
Code:
#pragma config(Hubs,  S1, MatrxRbtcs, none,     none,     none)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Motor,  motorA,          BeaterLeft,    tmotorNXT, PIDControl, encoder)
#pragma config(Motor,  motorB,          BeaterRight,   tmotorNXT, PIDControl, encoder)
#pragma config(Motor,  motorC,           ,             tmotorNXT, openLoop)
#pragma config(Motor,  mtr_Matrix_S1_1, LiftArm,       tmotorMatrix, PIDControl, encoder)
#pragma config(Motor,  mtr_Matrix_S1_2, motorE,        tmotorMatrix, openLoop)
#pragma config(Motor,  mtr_Matrix_S1_3, motorF,        tmotorMatrix, openLoop)
#pragma config(Motor,  mtr_Matrix_S1_4, motorG,        tmotorMatrix, openLoop)
#pragma config(Servo,  srvo_Matrix_S1_1, servo1,               tServoNone)
#pragma config(Servo,  srvo_Matrix_S1_2, servo2,               tServoNone)
#pragma config(Servo,  srvo_Matrix_S1_3, servo3,               tServoNone)
#pragma config(Servo,  srvo_Matrix_S1_4, servo4,               tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/* Here's where the work is done, main task is what is run when the program starts */
task main(){
   //Initialise starting positions
   nMotorEncoder[LiftArm]=0;
   nMotorEncoderTarget[LiftArm]=-1500;
   wait10Msec(10); //delay while variables are updated

   motor[LiftArm]=-80; //set power to the motor to run to the encoder target
   while (nMotorRunState[LiftArm] != runStateIdle ) {
      //do nothing until the encoder target is reached;
   }
   motor[LiftArm]=0; //stop the motor

   nMotorEncoderTarget[LiftArm]=-200; //set the motor to a new target position
   wait10Msec(10);

   motor[LiftArm]=80;
   while (nMotorRunState[LiftArm] != runStateIdle ) {
      //do nothing
   }
   motor[LiftArm]=0;
}

When the motor is set in PID mode in the pragma it just moves to a location once and sits there, regardless of the change in nMotorEncoderTarget values.
If we change it to OpenLoop the motor Always overshoots the encoder target and we end up trying to 'roll our own' PID style control and have it back up which results in a couple of seconds of shudder trying to find the exact target position.

There doesn't seem to be any reference in the RobotC help either about how to us the encoder target. The examples I've found don't seem to work either as they are waiting for motor state idle which only happens if you set a -ve value in the encoder target.

I'm tearing my hair out trying to make it work as intended, does anyone have any pointers?

Cheers
Cameron

Author:  johnnie-FTCSA [ Sun Jun 15, 2014 10:23 am ]
Post subject:  Re: Matrix motors & nMotorEncoderTarget

Hi

Did you figure it out because I am having the same problem?

---------------
Johnnie

Author:  cookthebook [ Mon Jun 16, 2014 12:38 am ]
Post subject:  Re: Matrix motors & nMotorEncoderTarget

The nMotorRunState didn't always work well for me. Although I do not use Matrix (I use Tetrix) you could try something analogous to this:
Code:
nMotorEncoder[LiftArm] = 0;
wait1Msec(50);

motor[LiftArm] = -80;
while(nMotorEncoder(LiftArm) >= -1500) {
}
motor[LiftArm]=0;

If it is over shooting by a ton, I would consider lowering the speed, but this worked reliably for me. If you are over shooting but still want some speed, consider changing the speed at different positions, slowing the motor incrementally.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/