Power Motor Control equivalent setting in nxc

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
jpotts
Posts: 1
Joined: 31 Dec 2011, 16:31

Power Motor Control equivalent setting in nxc

Post by jpotts »

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:

Code: Select all

RotateMotor(OUT_C, 50, 360);
The motor cannot shoot the ball, as expected. To turn on OUT_MODE_REGULATED, I tried to use:

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);
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
Attachments
rotate_power.rxe
(1.59 KiB) Downloaded 219 times
rotate_no_power.rxe
(1.59 KiB) Downloaded 218 times
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: Power Motor Control equivalent setting in nxc

Post by afanofosc »

The difference between the two programs is one sets the "UseSpeedControl" flag to true while the other leaves it false. Then later on there is code like this which configures the OutputMode and the RegMode differently based on that flag's value:

Code: Select all

	mov	theRegMode, OUT_REGMODE_IDLE
	mov	theOutputMode, OUT_MODE_MOTORON+OUT_MODE_BRAKE
        ; if UseSpeedRegulation == 0 then skip setting up speed regulation in OutputMode and RegMode
	brtst	EQ, lblNoSpeedRegulation, UseSpeedRegulation
	mov	theRegMode, OUT_REGMODE_SPEED
	mov	theOutputMode, OUT_MODE_MOTORON+OUT_MODE_BRAKE+OUT_MODE_REGULATED
lblNoSpeedRegulation:
So basically the trick is to set both RegMode to OUT_REGMODE_SPEED rather than OUT_REGMODE_IDLE and to include OUT_MODE_REGULATED in the OutputMode field's value. Of course, that is exactly what you tried using SetOutput so I am not entirely sure how to explain the lack of shooting ability at 50% power in NXC vs the Move block with Power Control turned on.

Here's a sample program I wrote today which shows how to use SetOutput and other code to implement a RotateMotor-like function of your own.
ex_ramping.nxc
(4.03 KiB) Downloaded 238 times
The Move block, iirc, uses RAMPUP and RAMPDOWN in addition to the RUNNING RunState something like how I wrote the RotateMotorRURD function in the attached file. I would try experimenting with this. You may need to fiddle with PID values as well since the ones I use in RotateMotor may not match the default values. A power cycle of the NXT should make sure that you will get the default PID values - at least until you run a program that uses the RotateMotor* official NXC API functions.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 0 guests