Subject:
|
Re: RotateMotorEx hangs
|
Newsgroups:
|
lugnet.robotics.nxt
|
Date:
|
Wed, 8 Aug 2007 22:20:21 GMT
|
Viewed:
|
22761 times
|
| |
| |
In lugnet.robotics.nxt, Roger Glassey wrote:
> In lugnet.robotics.nxt, Elizabeth Mabrey wrote:
> > Subject: RE: Idea on how to interrupt RotateMotor?
>
> Hi Elizabeth:
> Here is how you could do it in Java:
<snipped>
The RotateMotor call is designed to block. If you don't want to block then you
can write code almost exactly like what Roger wrote in Java using other NXC API
calls. Like so:
#define UF_TLSM UF_UPDATE_TACHO_LIMIT+UF_UPDATE_SPEED+UF_UPDATE_MODE
#define OM_RBM OUT_MODE_REGULATED+OUT_MODE_BRAKE+OUT_MODE_MOTORON
task main()
{
SetSensorLight(S1);
TextOut(0, LCD_LINE1, "wait for dark");
SetOutput(OUT_A, Power, 75, TachoLimit, 3600, RegMode, OUT_REGMODE_SPEED,
RunState, OUT_RUNSTATE_RUNNING, OutputMode, OM_RBM,
UpdateFlags, UF_TLSM);
// wait for dark or 10 revolutions
while((MotorRunState(OUT_A) == OUT_RUNSTATE_RUNNING) && (SENSOR_1 > 40));
Off(OUT_A);
NumOut(0, LCD_LINE2, MotorTachoCount(OUT_A));
Wait(10000); // to see the value on screen
}
The NXT firmware takes care of regulating the motor and it will stop
automatically at 3600 degrees. The SetOutput call can easily be wrapped into
any number of preprocessor macros or user-defined functions to further simplify
what is already trivially easy in NXC. The SetOutput call can take a variable
number of arguments so you can set any number of output fields that you want in
a single call. For synchronization just pass in OUT_AB or one of the other
paired motor constants and set the RegMode to OUT_REGMODE_SYNC instead of
OUT_REGMODE_SPEED.
John Hansen
|
|
Message is in Reply To:
| | Re: RotateMotorEx hangs
|
| (...) Hi Elizabeth: Here is how you could do it in Java: LightSensor eye = new LightSensor(SensorPort.S1); Motor.A.setSpeed(720); // 2 revolutions per second LCD.drawString("wait for dark",0,0); LCD.refresh(): Motor.A.rotate(3600,true); //rotate 10 (...) (17 years ago, 8-Aug-07, to lugnet.robotics.nxt)
|
8 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
Active threads in NXT programmable brick
|
|
|
|