Motor sensor as an input. need help

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
tjoshea13
Posts: 1
Joined: 08 Nov 2010, 15:40

Motor sensor as an input. need help

Post by tjoshea13 »

I would like to learn how to use the motor as a sensor as shown in this video
http://www.youtube.com/watch?v=k1Z7jqaeFgU

basically I want to make a joystick to drive a lego car that I am making.
All I need to know is how to sense the motor being turned as an input only.

I will be using BricxCC to program the robot. If anyone can help it would be greatly appreciated.
m-goldberg
Posts: 73
Joined: 29 Sep 2010, 12:05

Re: Motor sensor as an input. need help

Post by m-goldberg »

Look up MotorRotationCount in the NXC documentation. This is the API call you need to accomplish your task.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Motor sensor as an input. need help

Post by mattallen37 »

This working program should show you how to use it.

Code: Select all

task main()
{
  while(true)  //Repeat forever
  {
    TextOut(0,LCD_LINE3,"      ");  //Clear LCD line
    NumOut(0,LCD_LINE3,MotorTachoCount(OUT_A));  //Display tacho position
    if (ButtonPressed(BTN3,false)){ResetTachoCount(OUT_A);}  //Reset tacho count if left button pressed
    Wait(50);  //Slow the program down a little
  }
}
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: Motor sensor as an input. need help

Post by afanofosc »

Generally you should use MotorRotationCount rather than MotorTachoCount since the firmware may fiddle around with the latter while the former is left entirely up to the user to read and/or reset.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
chanyh
Posts: 17
Joined: 11 Oct 2010, 05:14

Re: Motor sensor as an input. need help

Post by chanyh »

If I know the MotorTachoCount(OUT_A), how do I make use of this data to allow the precise movement or further motion of the motor A?

Can anyone can help? Please give an example.

What is the difference between MotorTachoCount() and MotorRotationCount()?


YH Chan
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: Motor sensor as an input. need help

Post by afanofosc »

What, if anything, can you find out about these two functions and their similarities/differences from the NXC Help or Guide documents?

Some people have used the rotation count of a motor as a means for calculating a power level (kind of like a gas pedal) which can vary from -100 to 100. So you could use whatever positive or negative value you get from MotorRotationCount(port) either directly or scaled/limited to the allowed power range as the input to a motor control function for OUT_A. Such as OnFwd(OUT_A, pwr) where pwr is calculated as a function of the value returned by MotorRotationCount(OUT_C). Or you could use the output of MotorRotationCount(OUT_C) to specify the desired TachoLimit for OUT_A via the RotateMotor API function or by using the low level SetOutput API function. Exactly what to do depends entirely on what you want your robot to do. If you describe exactly what you want to have happen and post your own code that attempts to make that happen then you may get more feedback on how to modify/improve your code to make it do exactly what you tell us you want it to do.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
chanyh
Posts: 17
Joined: 11 Oct 2010, 05:14

Re: Motor sensor as an input. need help

Post by chanyh »

Hi, John,

Thanks!

YH Chan
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests