Power Motor Control equivalent setting in nxc
Posted: 31 Dec 2011, 16:40
I'm working through the NXT 2.0 Discovery Book (highly recommended) with my son and am porting some of the NXT G examples to nxc. We're working on the "roller shooter" robot and the author is pointing out the "Power Motor Control" option on the Motor block which I believe is used to regulate the power to the motor when it is under load. After looking through the nxc documentation, I believe the equivalent in nxc is OUT_MODE_REGULATED.
The exercise was to rotate the motor 360 degrees with 50% power. Without Power Motor Control the motor cannot shoot the ball. With the option turned
on the ball shoots because the motor increases power to overcome the load.
In nxc, when I use:
The motor cannot shoot the ball, as expected. To turn on OUT_MODE_REGULATED, I tried to use:
But this seemed to have the same problem as the RotateMotor call.
To work around this problem I ended up just increasing the power in the
RotateMotor call from 50 to 75. But that felt like cheating.
So my questions are:
1. What's the appropriate way to set and unset the equivalent Power Motor
Control flag?
2. If I wanted to use the SetOutput method, how would I restrict the motor
to a single revolution?
After an email exchange with John Hansen, I created two simple programs, one that has the Power Motor Control option set and one that does not. Both rotate the motor 360 degrees at 50% power. I have attached both rxe files.
Thanks for any tips/help you can provide.
Jeff
The exercise was to rotate the motor 360 degrees with 50% power. Without Power Motor Control the motor cannot shoot the ball. With the option turned
on the ball shoots because the motor increases power to overcome the load.
In nxc, when I use:
Code: Select all
RotateMotor(OUT_C, 50, 360);
Code: Select all
SetOutput(OUT_C, Power, 50,
OutputMode, OUT_MODE_BRAKE + OUT_MODE_MOTORON + OUT_MODE_REGULATED,
RegMode, OUT_REGMODE_SPEED
RunState, OUT_RUNSTATE_RUNNING,
UpdateFlags, UF_UPDATE_MODE + UF_UPDATE_SPEED);
To work around this problem I ended up just increasing the power in the
RotateMotor call from 50 to 75. But that felt like cheating.
So my questions are:
1. What's the appropriate way to set and unset the equivalent Power Motor
Control flag?
2. If I wanted to use the SetOutput method, how would I restrict the motor
to a single revolution?
After an email exchange with John Hansen, I created two simple programs, one that has the Power Motor Control option set and one that does not. Both rotate the motor 360 degrees at 50% power. I have attached both rxe files.
Thanks for any tips/help you can provide.
Jeff