NXC_MotorControl
Sends advanced motor-command to the NXC-program MotorControl on the NXT brick,
Contents
Syntax
NXC_MotorControl(Port, Power, TachoLimit, SpeedRegulation, ActionAtTachoLimit, SmoothStart)
NXC_MotorControl(Port, Power, TachoLimit, SpeedRegulation, ActionAtTachoLimit, SmoothStart, handle)
Description
The NXC-program "MotorControl" must be running on the brick, otherwise this function will not work. It is used to send advanced motor commands to the NXT that can perform better and more precise motor regulation than possible with only classic direct commands.
While one command is being executed (i.e. when the motor is still being controlled if a TachoLimit other than 0 was set), this motor cannot accept new commands. Use the NXTMotor classes command .WaitFor to make sure the motor has finished it's current operation, before sending a new one. If the NXC-program receives a new command while it is still busy, a warning signal (high beep, then low beep) will be played.
The command StopMotor (or NXTMotor's method .Stop) is always available to stop a controlled motor-operation, even before the TachoLimit is reached.
Input:
- Port has to be a port number between 0 and 2, or an array with max. 2 different motors specified.
- Power is the power level applied to the motor, value between -100 and 100 (sign changes direction)
- TachoLimit - integer from 0 to 999999, specifies the angle in degrees the motor will try to reach, set 0 to run forever. Note that direction is specified by the sign of Power.
- SpeedRegulation must be false for "normal", unregulated motor control. If set to true, single motors will be operated in speed regulation mode. This means that the motor will increase its internal power setting to reach a constant turning speed. Use this option when working with motors under varying load. If you'd like to have motor movement with preferrably constant torque, it's advisable to disable this option. In conjunction with multiple motors (i.e. when Port is an array of 2 ports), you have to disable SpeedRegulation! Multiple motorss will enable synchronization between the two motors. They will run at the same speed as if they were connected through and axle, leading to straight movement for driving bots.
- ActionAtTachoLimit is a string parameter with valid options 'Coast', 'Brake' or 'HoldBrake'. It specifies how the motor(s) should react when their position counter reaches the set TachoLimit. In COAST mode, the motor(s) will simply be turned of when the TachoLimit is reached, leading to free movement until slowly stopping (called coasting). The TachoLimit won't be met, the motor(s) move way too far (overshooting), depending on their angular momentum. Use BRAKE mode (default) to let the motor(s) automatically slow down nice and smoothly shortly before the TachoLimit. This leads to a very high precision, usually the TachoLimit is met within +/- 1 degree (depending on the motor load and speed of course). After this braking, power to the motor(s) is turned off when they are at rest. HOLDBRAKE is similar to BRAKE, but in this case, the active brake of the motors stays enabled (careful, this consumes a lot of battery power), causing the motor(s) to actively keep holding their position.
- SmoothStart can be set to true to smoothly accelerate movement. This "manual ramp up" of power will occur fairly quickly. It's comfortable for driving robots so that they don't loose traction when starting to move. If used in conjunction with SpeedRegulation for single motors, after accleration is finished and the full power is applied, the speed regulation can possibly even accelerate a bit more.
- handle (optional) defines the given NXT connection. If no handle is specified, the default one (COM_GetDefaultNXT()) is used.
Limitations
If you send a command to the NXT without waiting for the previous motor operation to have finished, the command will be dropped (the NXT indicates this with a high and low beep tone). Use NXTMotor classes WaitFor to make sure the motor is ready for new commands, or stop the motor using NXTMotor's method .Stop.
The option SmoothStart in conjunction with ActionAtTachoLimit == 'Coast' is not available. As a workaround, disable SmoothStart for this mode.
With ActionAtTachoLimit = 'Coast' and synchronous driving (two motors), the motors will stay synced after movement (even after .WaitFor() has finished). This is by design. To disable the synchonization, just use StopMotor(port, 'off').
See also
WaitForMotor, NXT_SetOutputState, NXT_GetOutputState, NXC_ResetErrorCorrection, MOTOR_A, MOTOR_B, MOTOR_C%
Signature
- Author: Linus Atorf (see AUTHORS)
- Date: 2009/07/20
- Copyright: 2007-2010, RWTH Aachen University