View unanswered posts | View active topics It is currently Fri Dec 09, 2016 3:55 am

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Motor Location ?
Author Message
Rookie

Joined: Sun Dec 02, 2012 7:05 am
Posts: 8
Motor Location ?
Hello guys
I've seen an NXC program that scans something and display it on the screen and i'm trying to do the same. After getting more into RobotC.

NXC code
 Code:   OnRev(OUT_B, -50);      Pos=abs(MotorTachoCount(OUT_B));      while ( Pos < width )

I suppose that Pos is the position of the motor.
Is there a function or do you have any idea how to get the location of the motor?

What i want to do with it is by defining the width of the display
while scanning using light or color sensor, the value will be checked when the value apply to the condition i'm having it will locate the position of the motor and will do a simple equation which is
x = screen width - (position of the motor * screen width) / width of travelling area
something like that
i'll leave you the full NXC code and i hope you might able to help me with

Last edited by SayedA7med on Tue Jan 22, 2013 3:22 pm, edited 1 time in total.

Fri Jan 18, 2013 4:46 pm
Senior Roboticist

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Re: Motor Location ?
Use this to get the tachometer reading from the motor.
 Code:nMotorEncoder[Motor];

Example:
 Code:while(true){  nxtDisplayCenteredBigTextLine(4, "%d", nMotorEncoder[motorA]);}

_________________
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.

Fri Jan 18, 2013 4:54 pm

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
Re: Motor Location ?
NeXT-Gen is correct, the command you are looking for is 'nMotorEncoder'. This will let you read and write values for the specified motor. For instance, to clear the motor's encoder to a value of zero:
 Code:nMotorEncoder[motorA] = 0;

There are multiple ways to keep a motor running until an encoder value is reached; one of the more common ways is to use a while loop:

 Code:nMotorEncoder[motorA] = 0; //Clear encoder valueswhile (nMotorEncoder[motorA] < 1000) //While the encoder value is less than 1000 ticks...{motor[motorA] = 50; //run motor A at a power level of 50...}motor[motorA] = 0;//but once the encoder value reaches 1000, exit the loop and stop the motor.

This will run motor A at a value of 50 power until it reaches 1000 encoder ticks; once 1000 encoder ticks are reached, the motors will turn off. Always make sure to either clear the encoders beforehand (or tweak your while loop condition accordingly) and to turn the motor off after the loop is over (if you want the motor to stop at that point).
You may notice that the motors drift past the desired encoder value by a bit; to avoid this, you will want to use the 'nMotorEncoderTarget' command:

 Code:nMotorEncoder[motorB] = 0;                // reset the Motor Encoder of Motor BnMotorEncoderTarget[motorB] = 360;        // set the  target for Motor Encoder of Motor B to 360 ticksmotor[motorB] = 75;                       // motor B is run at a power level of 75 while(nMotorRunState[motorB] != runStateIdle)  // while Motor B is still running (hasn't reached target yet):{  // do not continue to next line of code; stay in loop.}motor[motorB] = 0;                       // motor B is stopped at a power level of 0

To learn more about the encoder commands in ROBOTC, check out our NXT Motor Functions wiki page. You may also be interested in our [urlhttp://www.education.rec.ri.cmu.edu/previews/robot_c_products/teaching_rc_tetrix_preview/index.html]online curriculum video trainer[/url] which covers all of the basic ROBOTC commands and functions (including encoders and while loops).

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our updated help documentation and the ROBOTC Forums.

Fri Jan 18, 2013 5:17 pm
Rookie

Joined: Sun Dec 02, 2012 7:05 am
Posts: 8
Re: Motor Location ?
Thanks guys
That was so helpful

Sat Jan 19, 2013 4:33 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 4 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.