Page 1 of 1

Motor sensor as an input. need help

Posted: 08 Nov 2010, 16:00
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.

Re: Motor sensor as an input. need help

Posted: 08 Nov 2010, 16:21
by m-goldberg
Look up MotorRotationCount in the NXC documentation. This is the API call you need to accomplish your task.

Re: Motor sensor as an input. need help

Posted: 08 Nov 2010, 16:31
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
  }
}

Re: Motor sensor as an input. need help

Posted: 08 Nov 2010, 22:58
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

Re: Motor sensor as an input. need help

Posted: 09 Nov 2010, 00:36
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

Re: Motor sensor as an input. need help

Posted: 09 Nov 2010, 17:06
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

Re: Motor sensor as an input. need help

Posted: 09 Nov 2010, 18:39
by chanyh
Hi, John,

Thanks!

YH Chan