View unanswered posts | View active topics It is currently Mon Nov 24, 2014 4:07 am






Reply to topic  [ 8 posts ] 
ROBOTC motor programming 
Author Message
Rookie

Joined: Tue Oct 01, 2013 10:23 am
Posts: 13
Post 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!


Tue Oct 01, 2013 10:26 am
Profile
Site Admin
Site Admin
User avatar

Joined: Tue Oct 09, 2012 10:34 am
Posts: 192
Post 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

_________________
Ryan Cahoon
CMU Robotics Academy
RVW Software Developer

Robot Potato Head; Virtual NXT


Thu Oct 03, 2013 5:13 pm
Profile
Rookie

Joined: Tue Oct 01, 2013 10:23 am
Posts: 13
Post 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!


Wed Oct 09, 2013 9:55 am
Profile
Site Admin
Site Admin
User avatar

Joined: Tue Oct 09, 2012 10:34 am
Posts: 192
Post 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.

_________________
Ryan Cahoon
CMU Robotics Academy
RVW Software Developer

Robot Potato Head; Virtual NXT


Wed Oct 09, 2013 10:05 am
Profile
Rookie

Joined: Tue Oct 01, 2013 10:23 am
Posts: 13
Post 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!


Wed Oct 09, 2013 10:15 am
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post 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.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Wed Oct 09, 2013 10:20 am
Profile WWW
Rookie

Joined: Tue Oct 01, 2013 10:23 am
Posts: 13
Post Re: ROBOTC motor programming
aaa perfect thank you really really much!!!


Wed Oct 09, 2013 10:26 am
Profile
Rookie

Joined: Tue Oct 01, 2013 10:23 am
Posts: 13
Post 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!!!


Wed Oct 09, 2013 10:41 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 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.