ROBOTC.net forums
http://www.robotc.net/forums/

Macro functions and Motor precision/timing
http://www.robotc.net/forums/viewtopic.php?f=52&t=2110
Page 1 of 1

Author:  Warhawk [ Fri Jan 15, 2010 9:08 pm ]
Post subject:  Macro functions and Motor precision/timing

Hello everyone!

I would like to be able to create a code that allows my robot to perform multiple actions with the click of a single button. Along with that, i would like for my motors to be able to turn a specified amount during the command. I originally started with something along the lines of this:
Code:
if (//button one is pressed)
{
motor[motorA] = 100; //Motor at full power
wait1msec(60); //Allow the motor to turn for 60 milliseconds
}


but to my surprise when i pressed the button, the length of the spin was actually determined by the time I held down the button and was extremely inconsistant. If i pressed like normal the motor would spin for x long, but if i pressed it unrealisticly fast it would spin for x-y long...

I figured this was because the computer was executing the commands faster than i could move my finger, so the code was actually executing more than once. To combat this, i added:
Code:
motor[motorA] = 100; //Motor at full power
wait1msec(60); //Allow the motor to turn for 60 milliseconds
motor[motorA] = 0; //Turn off motor
wait1msec(100); //Give controller time to release button


I hoped, in vain, that the extra wait1msec would give the user time to press and release the button, but the effect was actually far more different... Instead the motor continued to spin the extra 100 milliseconds...


Is there a way to make the motor spin a certain amount in a given time with the use of a single button? Or better yet, do the HiTechnic DC motors have encoders i can use to specify the degree of the turn? (I know the servos do, but one of my senior club members told me the DC motors did not)

Thank you in advance!

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/