View unanswered posts | View active topics It is currently Fri May 25, 2018 2:50 pm

 Page 1 of 1 [ 8 posts ]
 Print view Previous topic | Next topic
ROBOTC motor programming
Author Message
Rookie

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

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

Robot Potato Head; Virtual NXT

Thu Oct 03, 2013 5:13 pm
Rookie

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

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

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
RVW Software Developer

Robot Potato Head; Virtual NXT

Wed Oct 09, 2013 10:05 am
Rookie

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

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

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

Wed Oct 09, 2013 10:26 am
Rookie

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

Thank you really much!!!

Wed Oct 09, 2013 10:41 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 8 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.