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.
Motor sensor as an input. need help
-
- Posts: 73
- Joined: 29 Sep 2010, 12:05
Re: Motor sensor as an input. need help
Look up MotorRotationCount in the NXC documentation. This is the API call you need to accomplish your task.
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Motor sensor as an input. need help
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
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: Motor sensor as an input. need help
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
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Re: Motor sensor as an input. need help
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
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
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
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/
http://bricxcc.sourceforge.net/
Re: Motor sensor as an input. need help
Hi, John,
Thanks!
YH Chan
Thanks!
YH Chan
Who is online
Users browsing this forum: Semrush [Bot] and 0 guests