View unanswered posts | View active topics It is currently Fri Nov 27, 2015 10:20 pm

Reply to topic  [ 3 posts ] 
Matrix motors & nMotorEncoderTarget 
Author Message

Joined: Mon Jan 27, 2014 7:29 am
Posts: 1
Post Matrix motors & nMotorEncoderTarget

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
#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
   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

   while (nMotorRunState[LiftArm] != runStateIdle ) {
      //do nothing

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?


Thu Jan 30, 2014 4:26 am

Joined: Sun Jun 15, 2014 9:37 am
Posts: 1
Post Re: Matrix motors & nMotorEncoderTarget

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


Sun Jun 15, 2014 10:23 am
User avatar

Joined: Wed Jan 09, 2013 11:48 pm
Posts: 46
Location: Saint Paul, MN
Post 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:
nMotorEncoder[LiftArm] = 0;

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

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.

Head Programmer FTC Team 6699, Tempest


Mon Jun 16, 2014 12:38 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.