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

ROBOTC motor programming
http://www.robotc.net/forums/viewtopic.php?f=1&t=6877
Page 1 of 1

Author:  jaruj9 [ Tue Oct 01, 2013 10:26 am ]
Post subject:  ROBOTC motor programming

Hay guys...i build my cnc from lego mut i have problem..I cant figure out how to turn two motors on the same time but just wor specifite nmotorencodor value. Both motors will have different values.

Can anyone help me please??

Thank you for time!

Author:  rcahoon [ Thu Oct 03, 2013 5:13 pm ]
Post subject:  Re: ROBOTC motor programming

Hi jaruj9,
From an example given on http://www.robotc.net/support/nxt/MindstormsWebHelp/index.htm#page=nxt_functions/Motors/Motors.htm

Code:
nMotorEncoder[motorB] = 0;                // Reset the Motor Encoder of Motor B.
nMotorEncoder[motorC] = 0;                // Reset the Motor Encoder of Motor C.
nMotorEncoderTarget[motorB] = 360;        // Set the  target for Motor Encoder of Motor B to 360.
nMotorEncoderTarget[motorC] = 360;        // Set the  target for Motor Encoder of Motor C to 360.
motor[motorB] = 75;                       // Motor B is run at a power level of 75.
motor[motorC] = 75;                       // Motor C is run at a power level of 75.

while(nMotorRunState[motorB] != runStateIdle && nMotorRunState[motorC] != runStateIdle) 
// While Motor B AND Motor C are still running (haven't yet reached their target):
{
  // Do not continue.
}
motor[motorB] = 0;                       // Motor B is stopped at a power level of 0.
motor[motorC] = 0;                       // Motor C is stopped at a power level of 0.


You can change the nMotorEncoderTarget and motor power values individually for each of the motors.

Cheers,
--Ryan

Author:  jaruj9 [ Wed Oct 09, 2013 9:55 am ]
Post subject:  Re: ROBOTC motor programming

Thank you for response!

But this function turn off both motors when one reach the possition. I need that, motor which will reach possition will turn off but the another which still did not will continue.

Tahank you!

Author:  rcahoon [ Wed Oct 09, 2013 10:05 am ]
Post subject:  Re: ROBOTC motor programming

jaruj9 wrote:
But this function turn off both motors when one reach the position. I need that, motor which will reach position will turn off but the another which still did not will continue.


My fault for not testing :oops:

The problem with the last code is that the wait while loop exited whenever either motor reached its target, but we want it to wait until both have reached their targets - in other words, we want to keep waiting while either motor is still running, instead of both motors running. We can do this by changing the "and" (&&) operator to an "or" (||) operator in the loop's condition:

Code:
nMotorEncoder[motorB] = 0;                // Reset the Motor Encoder of Motor B.
nMotorEncoder[motorC] = 0;                // Reset the Motor Encoder of Motor C.
nMotorEncoderTarget[motorB] = 360;        // Set the  target for Motor Encoder of Motor B to 360.
nMotorEncoderTarget[motorC] = 360;        // Set the  target for Motor Encoder of Motor C to 360.
motor[motorB] = 75;                       // Motor B is run at a power level of 75.
motor[motorC] = 75;                       // Motor C is run at a power level of 75.

while(nMotorRunState[motorB] != runStateIdle || nMotorRunState[motorC] != runStateIdle) 
// While Motor B OR Motor C are still running (haven't yet reached their target):
{
  // Do not continue.
}
motor[motorB] = 0;                       // Motor B is stopped at a power level of 0.
motor[motorC] = 0;                       // Motor C is stopped at a power level of 0.

Author:  jaruj9 [ Wed Oct 09, 2013 10:15 am ]
Post subject:  Re: ROBOTC motor programming

aaaa yesss thank you really much now it works!!

I have one more question. With the nmotorencoder overflow. The tutorial says that maximum counts is 32 767 but when I use for exampel 40 000 it works completelly good. My question is how is it possible?

Tahank you for your time!

Author:  NeXT-Generation [ Wed Oct 09, 2013 10:20 am ]
Post subject:  Re: ROBOTC motor programming

That information in the link rcahoon gave you is outdated. The encoder variable was upped from 16-bits to 32-bits a while ago. Resulting in +-~2,147,483,648 degree limit.

Author:  jaruj9 [ Wed Oct 09, 2013 10:26 am ]
Post subject:  Re: ROBOTC motor programming

aaa perfect thank you really really much!!!

Author:  jaruj9 [ Wed Oct 09, 2013 10:41 am ]
Post subject:  Re: ROBOTC motor programming

I found in that program one mistake!

In the case that one of the nmotorencoder value is 0(and the speed 0 too) the program does not continue after reach the position from another motor!
Can you please help me with this problem??

Thank you really much!!!

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