|
Files | |
file | MSMMUX-driver.h |
Mindsensors Motor MUX driver. | |
Defines | |
#define | MSMMUX_I2C_ADDR 0x06 |
#define | MSMMUX_REG_CMD 0x41 |
#define | MSMMUX_MOT_OFFSET 0x42 |
#define | MSMMUX_TARG_ENC 0x00 |
#define | MSMMUX_POWER 0x04 |
#define | MSMMUX_TARG_TIME 0x05 |
#define | MSMMUX_CMD_B 0x06 |
#define | MSMMUX_CMD_A 0x07 |
#define | MSMMUX_ENTRY_SIZE 0x08 |
#define | MSMMUX_TACHO_MOT1 0x62 |
#define | MSMMUX_TACHO_MOT2 0x66 |
#define | MSMMUX_STATUS_MOT1 0x72 |
#define | MSMMUX_STATUS_MOT2 0x73 |
#define | MSMMUX_KP_TACHO 0x7A |
#define | MSMMUX_KI_TACHO 0x7C |
#define | MSMMUX_KD_TACHO 0x7E |
#define | MSMMUX_KP_SPEED 0x80 |
#define | MSMMUX_KI_SPEED 0x82 |
#define | MSMMUX_KD_SPEED 0x84 |
#define | MSMMUX_PASSCOUNT 0x86 |
#define | MSMMUX_TOLERANCE 0x87 |
#define | MSMMUX_CMD_RESET_ALL 0x52 |
#define | MSMMUX_CMD_START_BOTH 0x53 |
#define | MSMMUX_CMD_FLOAT_MOT1 0x61 |
#define | MSMMUX_CMD_FLOAT_MOT2 0x62 |
#define | MSMMUX_CMD_FLOAT_BOTH 0x63 |
#define | MSMMUX_CMD_BRAKE_MOT1 0x41 |
#define | MSMMUX_CMD_BRAKE_MOT2 0x42 |
#define | MSMMUX_CMD_BRAKE_BOTH 0x43 |
#define | MSMMUX_CMD_RESET_MOT1 0x72 |
#define | MSMMUX_CMD_RESET_MOT2 0x73 |
#define | MSMMUX_STAT_SPEED_CTRL (0x01 << 0) |
#define | MSMMUX_STAT_RAMPING (0x01 << 1) |
#define | MSMMUX_STAT_POWERED (0x01 << 2) |
#define | MSMMUX_STAT_POS_CTRL (0x01 << 3) |
#define | MSMMUX_STAT_BRAKED (0x01 << 4) |
#define | MSMMUX_STAT_OVERLOADED (0x01 << 5) |
#define | MSMMUX_STAT_TIMED (0x01 << 6) |
#define | MSMMUX_STAT_STALLED (0x01 << 7) |
#define | MSMMUX_CMD_SPEED 0x01 |
#define | MSMMUX_CMD_RAMP 0x02 |
#define | MSMMUX_CMD_RELATIVE 0x04 |
#define | MSMMUX_CMD_TACHO 0x08 |
#define | MSMMUX_CMD_BRK 0x10 |
#define | MSMMUX_CMD_HOLDPOS 0x20 |
#define | MSMMUX_CMD_TIME 0x40 |
#define | MSMMUX_CMD_GO 0x80 |
#define | MSMMUX_RAMP_NONE 0x00 |
#define | MSMMUX_RAMP_UP_DOWN 0x03 |
#define | MSMMUX_ROT_UNLIMITED 0x00 |
#define | MSMMUX_ROT_DEGREES 0x01 |
#define | MSMMUX_ROT_SECONDS 0x03 |
Functions | |
void | MSMMUXinit () |
bool | MSMMUXreadStatus (tMUXmotor muxmotor, ubyte &motorStatus) |
bool | MSMMUXsendCommand (tSensors link, ubyte channel, long setpoint, byte speed, ubyte seconds, ubyte commandA) |
bool | MSMMUXsendCommand (tSensors link, ubyte command) |
bool | MSMMUXsetPID (tSensors link, int kpTacho, int kiTacho, int kdTacho, int kpSpeed, int kiSpeed, int kdSpeed, ubyte passCount, ubyte tolerance) |
bool | MSMMotor (tMUXmotor muxmotor, byte power) |
bool | MSMotorStop (tMUXmotor muxmotor) |
bool | MSMotorStop (tMUXmotor muxmotor, bool brake) |
void | MSMMotorSetRotationTarget (tMUXmotor muxmotor, long target) |
void | MSMMotorSetTimeTarget (tMUXmotor muxmotor, int target) |
void | MSMMotorSetEncoderTarget (tMUXmotor muxmotor, long target) |
void | MSMMotorSetEncoderTarget (tMUXmotor muxmotor, long target, bool relative) |
long | MSMMotorEncoder (tMUXmotor muxmotor) |
bool | MSMMotorEncoderReset (tMUXmotor muxmotor) |
bool | MSMMotorEncoderResetAll (tSensors link) |
bool | MSMMotorBusy (tMUXmotor muxmotor) |
bool | MSMMotorStalled (tMUXmotor muxmotor) |
void | MSMMotorSetBrake (tMUXmotor muxmotor) |
void | MSMMotorSetFloat (tMUXmotor muxmotor) |
void | MSMMotorSetSpeedCtrl (tMUXmotor muxmotor, bool constspeed) |
void | MSMMotorSetRamping (tMUXmotor muxmotor, bool ramping) |
Variables | |
tByteArray | MSMMUX_I2CRequest |
tByteArray | MSMMUX_I2CReply |
NXT Motor MUX
#define MSMMUX_CMD_A 0x07 |
Command A regiser
Definition at line 55 of file MSMMUX-driver.h.
#define MSMMUX_CMD_B 0x06 |
Command B register - for future use
Definition at line 54 of file MSMMUX-driver.h.
#define MSMMUX_CMD_BRAKE_BOTH 0x43 |
Stop both motors and brake
Definition at line 80 of file MSMMUX-driver.h.
#define MSMMUX_CMD_BRAKE_MOT1 0x41 |
Stop motor 1 and brake
Definition at line 78 of file MSMMUX-driver.h.
#define MSMMUX_CMD_BRAKE_MOT2 0x42 |
Stop motor 2 and brake
Definition at line 79 of file MSMMUX-driver.h.
#define MSMMUX_CMD_BRK 0x10 |
Whether to brake (1) or float (0) when motor has reached its target
Definition at line 99 of file MSMMUX-driver.h.
#define MSMMUX_CMD_FLOAT_BOTH 0x63 |
Stop both motors and allow to float
Definition at line 77 of file MSMMUX-driver.h.
#define MSMMUX_CMD_FLOAT_MOT1 0x61 |
Stop motor 1 and allow to float
Definition at line 75 of file MSMMUX-driver.h.
#define MSMMUX_CMD_FLOAT_MOT2 0x62 |
Stop motor 2 and allow to float
Definition at line 76 of file MSMMUX-driver.h.
#define MSMMUX_CMD_GO 0x80 |
Instruct the MUX to start the motors using the current registers
Definition at line 102 of file MSMMUX-driver.h.
#define MSMMUX_CMD_HOLDPOS 0x20 |
Motor will hold position when this is enabled and push back when moved
Definition at line 100 of file MSMMUX-driver.h.
#define MSMMUX_CMD_RAMP 0x02 |
Ramp the speed up or down
Definition at line 96 of file MSMMUX-driver.h.
#define MSMMUX_CMD_RELATIVE 0x04 |
Make encoder target relative to current position
Definition at line 97 of file MSMMUX-driver.h.
#define MSMMUX_CMD_RESET_ALL 0x52 |
Reset the tachos and motor values
Definition at line 73 of file MSMMUX-driver.h.
#define MSMMUX_CMD_RESET_MOT1 0x72 |
Reset the encoder count for motor 1
Definition at line 81 of file MSMMUX-driver.h.
#define MSMMUX_CMD_RESET_MOT2 0x73 |
Reset the encoder count for motor 2
Definition at line 82 of file MSMMUX-driver.h.
#define MSMMUX_CMD_SPEED 0x01 |
Speed control of your motor
Definition at line 95 of file MSMMUX-driver.h.
#define MSMMUX_CMD_START_BOTH 0x53 |
Start both motors with parameters in motor registers
Definition at line 74 of file MSMMUX-driver.h.
#define MSMMUX_CMD_TACHO 0x08 |
Use the encoder target to control motor
Definition at line 98 of file MSMMUX-driver.h.
#define MSMMUX_CMD_TIME 0x40 |
Use the time target to control the motor
Definition at line 101 of file MSMMUX-driver.h.
#define MSMMUX_ENTRY_SIZE 0x08 |
Number of registers per motor channel
Definition at line 56 of file MSMMUX-driver.h.
#define MSMMUX_I2C_ADDR 0x06 |
MSMMUX I2C device address
Definition at line 45 of file MSMMUX-driver.h.
#define MSMMUX_KD_SPEED 0x84 |
Kd for Speed Control
Definition at line 68 of file MSMMUX-driver.h.
#define MSMMUX_KD_TACHO 0x7E |
Kd for Tachometer Position Control
Definition at line 65 of file MSMMUX-driver.h.
#define MSMMUX_KI_SPEED 0x82 |
Ki for Speed Control
Definition at line 67 of file MSMMUX-driver.h.
#define MSMMUX_KI_TACHO 0x7C |
Ki for Tachometer Position Control
Definition at line 64 of file MSMMUX-driver.h.
#define MSMMUX_KP_SPEED 0x80 |
Kp for Speed Control
Definition at line 66 of file MSMMUX-driver.h.
#define MSMMUX_KP_TACHO 0x7A |
Kp for Tachometer Position Control
Definition at line 63 of file MSMMUX-driver.h.
#define MSMMUX_MOT_OFFSET 0x42 |
Motor regiser offset
Definition at line 50 of file MSMMUX-driver.h.
#define MSMMUX_PASSCOUNT 0x86 |
Encoder count tolerance when motor is moving
Definition at line 69 of file MSMMUX-driver.h.
#define MSMMUX_POWER 0x04 |
Motor power
Definition at line 52 of file MSMMUX-driver.h.
#define MSMMUX_RAMP_NONE 0x00 |
Use no ramping at all
Definition at line 104 of file MSMMUX-driver.h.
#define MSMMUX_RAMP_UP_DOWN 0x03 |
Use ramping to bring motor up to speed or to a halt
Definition at line 105 of file MSMMUX-driver.h.
#define MSMMUX_REG_CMD 0x41 |
Command register
Definition at line 48 of file MSMMUX-driver.h.
#define MSMMUX_ROT_DEGREES 0x01 |
Use encoder target to control motor (ie rotate motor X number of degrees)
Definition at line 108 of file MSMMUX-driver.h.
#define MSMMUX_ROT_SECONDS 0x03 |
Use time target to control motor (ie run for X seconds)
Definition at line 110 of file MSMMUX-driver.h.
#define MSMMUX_ROT_UNLIMITED 0x00 |
Allow motor to rotate forever (or until batteries run out, of course)
Definition at line 107 of file MSMMUX-driver.h.
#define MSMMUX_STAT_BRAKED (0x01 << 4) |
Motor is braked. 0 means motor is floating
Definition at line 89 of file MSMMUX-driver.h.
#define MSMMUX_STAT_OVERLOADED (0x01 << 5) |
Set to 1 when motor can't achieve desired speed
Definition at line 90 of file MSMMUX-driver.h.
#define MSMMUX_STAT_POS_CTRL (0x01 << 3) |
Motor is either moving towards target or holding position.
Definition at line 88 of file MSMMUX-driver.h.
#define MSMMUX_STAT_POWERED (0x01 << 2) |
Motor is powered, does not imply movement
Definition at line 87 of file MSMMUX-driver.h.
#define MSMMUX_STAT_RAMPING (0x01 << 1) |
Motor is currently ramping up or down
Definition at line 86 of file MSMMUX-driver.h.
#define MSMMUX_STAT_SPEED_CTRL (0x01 << 0) |
Motor is programmed to move at a fixed speed.
Definition at line 85 of file MSMMUX-driver.h.
#define MSMMUX_STAT_STALLED (0x01 << 7) |
Motor is stalled
Definition at line 92 of file MSMMUX-driver.h.
#define MSMMUX_STAT_TIMED (0x01 << 6) |
Motor is running for a specified duration
Definition at line 91 of file MSMMUX-driver.h.
#define MSMMUX_STATUS_MOT1 0x72 |
Status for motor 1
Definition at line 59 of file MSMMUX-driver.h.
#define MSMMUX_STATUS_MOT2 0x73 |
Status for motor 2
Definition at line 60 of file MSMMUX-driver.h.
#define MSMMUX_TACHO_MOT1 0x62 |
Tacho count for motor 1
Definition at line 57 of file MSMMUX-driver.h.
#define MSMMUX_TACHO_MOT2 0x66 |
Tacho count for motor 2
Definition at line 58 of file MSMMUX-driver.h.
#define MSMMUX_TARG_ENC 0x00 |
Target encoder value
Definition at line 51 of file MSMMUX-driver.h.
#define MSMMUX_TARG_TIME 0x05 |
Time target value
Definition at line 53 of file MSMMUX-driver.h.
#define MSMMUX_TOLERANCE 0x87 |
Encoder count tolerance when motor is getting close to target
Definition at line 70 of file MSMMUX-driver.h.
bool MSMMotor | ( | tMUXmotor | muxmotor, |
byte | power | ||
) |
Run motor with specified speed.
muxmotor | the motor-MUX motor |
power | power the amount of power to apply to the motor, value between -100 and +100 |
Definition at line 296 of file MSMMUX-driver.h.
bool MSMMotorBusy | ( | tMUXmotor | muxmotor ) |
Check if the specified motor is running or not.
muxmotor | the motor-MUX motor |
Definition at line 473 of file MSMMUX-driver.h.
long MSMMotorEncoder | ( | tMUXmotor | muxmotor ) |
Fetch the current encoder value for specified motor channel
muxmotor | the motor-MUX motor |
Definition at line 409 of file MSMMUX-driver.h.
bool MSMMotorEncoderReset | ( | tMUXmotor | muxmotor ) |
Reset target encoder for specified motor channel, use only at the start of your program. If you are using the standard NXT wheels you will not run into problems with a wrap-around for the first 500kms or so.
muxmotor | the motor-MUX motor |
Definition at line 444 of file MSMMUX-driver.h.
bool MSMMotorEncoderResetAll | ( | tSensors | link ) |
Reset all encoders on the specified motor-MUX. Use only at the start of your program. If you are using the standard NXT wheels you will not run into problems with a wrap-around for the first 500kms or so.
link | the MMUX port number |
Definition at line 462 of file MSMMUX-driver.h.
void MSMMotorSetBrake | ( | tMUXmotor | muxmotor ) |
Set the stopping method for the specified motor to brake.
muxmotor | the motor-MUX motor |
Definition at line 530 of file MSMMUX-driver.h.
void MSMMotorSetEncoderTarget | ( | tMUXmotor | muxmotor, |
long | target | ||
) |
Set encoder target for specified mux motor. Target is relative to current position.
muxmotor | the motor-MUX motor |
target | the encoder target value in degrees. |
Definition at line 381 of file MSMMUX-driver.h.
void MSMMotorSetEncoderTarget | ( | tMUXmotor | muxmotor, |
long | target, | ||
bool | relative | ||
) |
Set encoder target for specified mux motor.
muxmotor | the motor-MUX motor |
target | the encoder target value in degrees. |
relative | specified target is relative to current position. |
Definition at line 396 of file MSMMUX-driver.h.
void MSMMotorSetFloat | ( | tMUXmotor | muxmotor ) |
Set the stopping method for the specified motor to float.
muxmotor | the motor-MUX motor |
Definition at line 540 of file MSMMUX-driver.h.
void MSMMotorSetRamping | ( | tMUXmotor | muxmotor, |
bool | ramping | ||
) |
Set the ramping control for the specified motor.
muxmotor | the motor-MUX motor |
ramping | use ramping for starting and stopping the motor |
Definition at line 562 of file MSMMUX-driver.h.
void MSMMotorSetRotationTarget | ( | tMUXmotor | muxmotor, |
long | target | ||
) |
Set rotation target for specified mux motor.
muxmotor | the motor-MUX motor |
target | the rotation target value |
Definition at line 354 of file MSMMUX-driver.h.
void MSMMotorSetSpeedCtrl | ( | tMUXmotor | muxmotor, |
bool | constspeed | ||
) |
Set the motor speed control for the specified motor.
muxmotor | the motor-MUX motor |
constspeed | use speed control to ensure motor speed stays constant under varying load |
Definition at line 551 of file MSMMUX-driver.h.
void MSMMotorSetTimeTarget | ( | tMUXmotor | muxmotor, |
int | target | ||
) |
Set time target for specified mux motor. Seconds can be specified in increments of 1 second with an upper limit of 255 seconds.
muxmotor | the motor-MUX motor |
target | the time target value in seconds [1-255] |
Definition at line 368 of file MSMMUX-driver.h.
bool MSMMotorStalled | ( | tMUXmotor | muxmotor ) |
Check if the specified motor is running or not.
muxmotor | the motor-MUX motor |
Definition at line 516 of file MSMMUX-driver.h.
void MSMMUXinit | ( | ) |
Definition at line 143 of file MSMMUX-driver.h.
bool MSMMUXreadStatus | ( | tMUXmotor | muxmotor, |
ubyte & | motorStatus | ||
) |
Read the status byte of the specified motor
muxmotor | the motor-MUX motor |
motorStatus | status of the motor |
Definition at line 163 of file MSMMUX-driver.h.
bool MSMMUXsendCommand | ( | tSensors | link, |
ubyte | channel, | ||
long | setpoint, | ||
byte | speed, | ||
ubyte | seconds, | ||
ubyte | commandA | ||
) |
Send a command to the MMUX.
Note: this is an internal function and shouldn't be used directly
link | the MMUX port number |
channel | the channel the command should apply to |
setpoint | the encoder count the motor should move to |
speed | the speed the motor should move at |
seconds | the number of seconds the motor should run for. Note that this takes precedence over the encoder target |
commandA | the command to be sent to the motor |
Definition at line 199 of file MSMMUX-driver.h.
bool MSMMUXsendCommand | ( | tSensors | link, |
ubyte | command | ||
) |
Send a command to the MMUX.
Note: this is an internal function and shouldn't be used directly
link | the MMUX port number |
command | the command to be sent to the motor |
Definition at line 231 of file MSMMUX-driver.h.
bool MSMMUXsetPID | ( | tSensors | link, |
int | kpTacho, | ||
int | kiTacho, | ||
int | kdTacho, | ||
int | kpSpeed, | ||
int | kiSpeed, | ||
int | kdSpeed, | ||
ubyte | passCount, | ||
ubyte | tolerance | ||
) |
Configure the internal PID controller. Tweaking these values will change the behaviour of the motors, how they approach their target, how they maintain speed, etc. These settings do not persist, disconnecting the MUX will reset these values to their defaults. These settings are MUX-wide, so will apply to how BOTH motors are controlled.
Please refer to the User Guide for more detailed information on how these parameters should be used.
link | the MMUX port number |
kpTacho | Kp for Tachometer Position Control |
kiTacho | Ki for Tachometer Position Control |
kdTacho | Kd for Tachometer Position Control |
kpSpeed | Kp for Speed Control |
kiSpeed | Ki for Speed Control |
kdSpeed | Kd for Speed Control |
passCount | Encoder count tolerance when motor is moving |
tolerance | Encoder count tolerance when motor is getting close to target |
Definition at line 264 of file MSMMUX-driver.h.
bool MSMotorStop | ( | tMUXmotor | muxmotor, |
bool | brake | ||
) |
Stop the motor. This function overrides the preconfigured braking method.
muxmotor | the motor-MUX motor |
brake | when set to true: use brake, false: use float |
Definition at line 338 of file MSMMUX-driver.h.
bool MSMotorStop | ( | tMUXmotor | muxmotor ) |
Stop the motor. Uses the brake method specified with MSMMotorSetBrake or MSMMotorSetFloat. The default is to use braking.
muxmotor | the motor-MUX motor |
Definition at line 322 of file MSMMUX-driver.h.
Array to hold I2C reply data
Definition at line 114 of file MSMMUX-driver.h.
Array to hold I2C command data
Definition at line 113 of file MSMMUX-driver.h.