MCL Scripting: Power Commands

Introduction

The power and power2 commands in the MCL language are used to set the duty cycle and acceleration for one or both motor channels. This article covers the usage of both commands and lists example code to demonstrate their usage. The example code can be downloaded from Github.

Power Command

The power command sets the duty cycle and acceleration for one motor channel at a time, either motor channel can be operated.

Format:

power motor, duty, accel

Arguments:

Motor: 0 for motor 1, 1 for motor 2
Duty: The value ranges from -32,767 to 32,767. Positive values are forward motion and negative values are backwards motion. O denotes stop.
Acceleration: The acceleration value is calculated as follows:

Change in duty / inverse of time in seconds

For a duty of 32767 in one second: 32767/1 = 32767
For a duty of 32767 in two seconds: 32767/0.5 = 65534
For a duty of 32767 in a half second: 32767/2 = 16384

Example:

main

power 0, 16384, 16384 ; motor 1 forward at half duty
pause 2000
power 0, 0, 16384 ; motor 1 stop
pause 2000
power 0, -16384, 16384 ; motor 1 backwards at half duty
pause 2000
power 0, 0, 16384 ; motor 1 stop
pause 2000

power 1, 16384, 16384 ; motor 2 forward at half duty
pause 2000
power 1, 0, 16384 ; motor 2 stop
pause 2000
power 1, -16384, 16384 ; motor 2 backwards at half duty
pause 2000
power 1, 0, 16384 ; motor 2 stop
pause 2000
goto main

The example code can be downloaded from GitHub here.

Power2 Command

The power2 command sets the duty cycle and acceleration for both motor channels at the same time.

Format:

power2 duty1, accel1, duty2, accel2

Arguments:

Duty1/2: The duty of motor 1 and motor 2 respectively. The value ranges from -32,767 to 32,767. Positive values are forward motion and negative values are backwards motion. O denotes stop.
Accel1/2: The acceleration for motor 1 and motor 2 respectively. The acceleration value is calculated as follows:

Change in duty / inverse of time in seconds

For a duty of 32767 in one second: 32767/1 = 32767
For a duty of 32767 in two seconds: 32767/0.5 = 65534
For a duty of 32767 in a half second: 32767/2 = 16384

Example:

main

power2 16384, 16384, 16384, 16384 ; both motors forward
pause 4000
power2 0, 16384, 0, 16384 ; both motors stopped
pause 4000
power2 -16384, 16384, -16384, 16384 ; both motors backwards
pause 4000
power2 0, 16384, 0, 16384 ; both motors stopped
pause 4000
power2 16384, 16384, -16384, 16384 ; motor 1 forward motor 2 backwards
pause 4000
power2 0, 16384, 0, 16384 ; both motors stopped
pause 4000
power2 -16384, 16384, 16384, 16384 ; motor 1 backwards motor 2 forward
pause 4000
power2 0, 16384, 0, 16384 ; both motors stopped
pause 4000
goto main

The example code can be downloaded from GitHub here.