|
Files | |
file | mindsensors-motormux.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, ubyte address=MSMMUX_I2C_ADDR) |
bool | MSMMUXsendCommand (tSensors link, ubyte command, ubyte address=MSMMUX_I2C_ADDR) |
bool | MSMMUXsetPID (tSensors link, unsigned int kpTacho, unsigned int kiTacho, unsigned int kdTacho, unsigned int kpSpeed, unsigned int kiSpeed, unsigned int kdSpeed, ubyte passCount, ubyte tolerance, ubyte address=MSMMUX_I2C_ADDR) |
bool | MSMMotor (tMUXmotor muxmotor, byte power, ubyte address=MSMMUX_I2C_ADDR) |
bool | MSMotorStop (tMUXmotor muxmotor, ubyte address=MSMMUX_I2C_ADDR) |
bool | MSMotorStop (tMUXmotor muxmotor, bool brake, ubyte address=MSMMUX_I2C_ADDR) |
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, ubyte address=MSMMUX_I2C_ADDR) |
bool | MSMMotorEncoderReset (tMUXmotor muxmotor, ubyte address=MSMMUX_I2C_ADDR) |
bool | MSMMotorEncoderResetAll (tSensors link, ubyte address=MSMMUX_I2C_ADDR) |
bool | MSMMotorBusy (tMUXmotor muxmotor, ubyte address=MSMMUX_I2C_ADDR) |
bool | MSMMotorStalled (tMUXmotor muxmotor, ubyte address=MSMMUX_I2C_ADDR) |
void | MSMMotorSetBrake (tMUXmotor muxmotor) |
void | MSMMotorSetFloat (tMUXmotor muxmotor) |
void | MSMMotorSetSpeedCtrl (tMUXmotor muxmotor, bool constspeed) |
void | MSMMotorSetRamping (tMUXmotor muxmotor, bool ramping) |
bool | MSMMUXreadStatus (tMUXmotor muxmotor, ubyte &motorStatus, ubyte address) |
Variables | |
tByteArray | MSMMUX_I2CRequest |
tByteArray | MSMMUX_I2CReply |
NXT Motor MUX
#define MSMMUX_CMD_A 0x07 |
Command A regiser
Definition at line 56 of file mindsensors-motormux.h.
#define MSMMUX_CMD_B 0x06 |
Command B register - for future use
Definition at line 55 of file mindsensors-motormux.h.
#define MSMMUX_CMD_BRAKE_BOTH 0x43 |
Stop both motors and brake
Definition at line 81 of file mindsensors-motormux.h.
#define MSMMUX_CMD_BRAKE_MOT1 0x41 |
Stop motor 1 and brake
Definition at line 79 of file mindsensors-motormux.h.
#define MSMMUX_CMD_BRAKE_MOT2 0x42 |
Stop motor 2 and brake
Definition at line 80 of file mindsensors-motormux.h.
#define MSMMUX_CMD_BRK 0x10 |
Whether to brake (1) or float (0) when motor has reached its target
Definition at line 100 of file mindsensors-motormux.h.
#define MSMMUX_CMD_FLOAT_BOTH 0x63 |
Stop both motors and allow to float
Definition at line 78 of file mindsensors-motormux.h.
#define MSMMUX_CMD_FLOAT_MOT1 0x61 |
Stop motor 1 and allow to float
Definition at line 76 of file mindsensors-motormux.h.
#define MSMMUX_CMD_FLOAT_MOT2 0x62 |
Stop motor 2 and allow to float
Definition at line 77 of file mindsensors-motormux.h.
#define MSMMUX_CMD_GO 0x80 |
Instruct the MUX to start the motors using the current registers
Definition at line 103 of file mindsensors-motormux.h.
#define MSMMUX_CMD_HOLDPOS 0x20 |
Motor will hold position when this is enabled and push back when moved
Definition at line 101 of file mindsensors-motormux.h.
#define MSMMUX_CMD_RAMP 0x02 |
Ramp the speed up or down
Definition at line 97 of file mindsensors-motormux.h.
#define MSMMUX_CMD_RELATIVE 0x04 |
Make encoder target relative to current position
Definition at line 98 of file mindsensors-motormux.h.
#define MSMMUX_CMD_RESET_ALL 0x52 |
Reset the tachos and motor values
Definition at line 74 of file mindsensors-motormux.h.
#define MSMMUX_CMD_RESET_MOT1 0x72 |
Reset the encoder count for motor 1
Definition at line 82 of file mindsensors-motormux.h.
#define MSMMUX_CMD_RESET_MOT2 0x73 |
Reset the encoder count for motor 2
Definition at line 83 of file mindsensors-motormux.h.
#define MSMMUX_CMD_SPEED 0x01 |
Speed control of your motor
Definition at line 96 of file mindsensors-motormux.h.
#define MSMMUX_CMD_START_BOTH 0x53 |
Start both motors with parameters in motor registers
Definition at line 75 of file mindsensors-motormux.h.
#define MSMMUX_CMD_TACHO 0x08 |
Use the encoder target to control motor
Definition at line 99 of file mindsensors-motormux.h.
#define MSMMUX_CMD_TIME 0x40 |
Use the time target to control the motor
Definition at line 102 of file mindsensors-motormux.h.
#define MSMMUX_ENTRY_SIZE 0x08 |
Number of registers per motor channel
Definition at line 57 of file mindsensors-motormux.h.
#define MSMMUX_I2C_ADDR 0x06 |
MSMMUX I2C device address
Definition at line 46 of file mindsensors-motormux.h.
#define MSMMUX_KD_SPEED 0x84 |
Kd for Speed Control
Definition at line 69 of file mindsensors-motormux.h.
#define MSMMUX_KD_TACHO 0x7E |
Kd for Tachometer Position Control
Definition at line 66 of file mindsensors-motormux.h.
#define MSMMUX_KI_SPEED 0x82 |
Ki for Speed Control
Definition at line 68 of file mindsensors-motormux.h.
#define MSMMUX_KI_TACHO 0x7C |
Ki for Tachometer Position Control
Definition at line 65 of file mindsensors-motormux.h.
#define MSMMUX_KP_SPEED 0x80 |
Kp for Speed Control
Definition at line 67 of file mindsensors-motormux.h.
#define MSMMUX_KP_TACHO 0x7A |
Kp for Tachometer Position Control
Definition at line 64 of file mindsensors-motormux.h.
#define MSMMUX_MOT_OFFSET 0x42 |
Motor regiser offset
Definition at line 51 of file mindsensors-motormux.h.
#define MSMMUX_PASSCOUNT 0x86 |
Encoder count tolerance when motor is moving
Definition at line 70 of file mindsensors-motormux.h.
#define MSMMUX_POWER 0x04 |
Motor power
Definition at line 53 of file mindsensors-motormux.h.
#define MSMMUX_RAMP_NONE 0x00 |
Use no ramping at all
Definition at line 105 of file mindsensors-motormux.h.
#define MSMMUX_RAMP_UP_DOWN 0x03 |
Use ramping to bring motor up to speed or to a halt
Definition at line 106 of file mindsensors-motormux.h.
#define MSMMUX_REG_CMD 0x41 |
Command register
Definition at line 49 of file mindsensors-motormux.h.
#define MSMMUX_ROT_DEGREES 0x01 |
Use encoder target to control motor (ie rotate motor X number of degrees)
Definition at line 109 of file mindsensors-motormux.h.
#define MSMMUX_ROT_SECONDS 0x03 |
Use time target to control motor (ie run for X seconds)
Definition at line 111 of file mindsensors-motormux.h.
#define MSMMUX_ROT_UNLIMITED 0x00 |
Allow motor to rotate forever (or until batteries run out, of course)
Definition at line 108 of file mindsensors-motormux.h.
#define MSMMUX_STAT_BRAKED (0x01 << 4) |
Motor is braked. 0 means motor is floating
Definition at line 90 of file mindsensors-motormux.h.
#define MSMMUX_STAT_OVERLOADED (0x01 << 5) |
Set to 1 when motor can't achieve desired speed
Definition at line 91 of file mindsensors-motormux.h.
#define MSMMUX_STAT_POS_CTRL (0x01 << 3) |
Motor is either moving towards target or holding position.
Definition at line 89 of file mindsensors-motormux.h.
#define MSMMUX_STAT_POWERED (0x01 << 2) |
Motor is powered, does not imply movement
Definition at line 88 of file mindsensors-motormux.h.
#define MSMMUX_STAT_RAMPING (0x01 << 1) |
Motor is currently ramping up or down
Definition at line 87 of file mindsensors-motormux.h.
#define MSMMUX_STAT_SPEED_CTRL (0x01 << 0) |
Motor is programmed to move at a fixed speed.
Definition at line 86 of file mindsensors-motormux.h.
#define MSMMUX_STAT_STALLED (0x01 << 7) |
Motor is stalled
Definition at line 93 of file mindsensors-motormux.h.
#define MSMMUX_STAT_TIMED (0x01 << 6) |
Motor is running for a specified duration
Definition at line 92 of file mindsensors-motormux.h.
#define MSMMUX_STATUS_MOT1 0x72 |
Status for motor 1
Definition at line 60 of file mindsensors-motormux.h.
#define MSMMUX_STATUS_MOT2 0x73 |
Status for motor 2
Definition at line 61 of file mindsensors-motormux.h.
#define MSMMUX_TACHO_MOT1 0x62 |
Tacho count for motor 1
Definition at line 58 of file mindsensors-motormux.h.
#define MSMMUX_TACHO_MOT2 0x66 |
Tacho count for motor 2
Definition at line 59 of file mindsensors-motormux.h.
#define MSMMUX_TARG_ENC 0x00 |
Target encoder value
Definition at line 52 of file mindsensors-motormux.h.
#define MSMMUX_TARG_TIME 0x05 |
Time target value
Definition at line 54 of file mindsensors-motormux.h.
#define MSMMUX_TOLERANCE 0x87 |
Encoder count tolerance when motor is getting close to target
Definition at line 71 of file mindsensors-motormux.h.
bool MSMMotor | ( | tMUXmotor | muxmotor, |
byte | power, | ||
ubyte | address | ||
) |
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 |
address | I2C address of the sensor (optional) |
Definition at line 299 of file mindsensors-motormux.h.
bool MSMMotorBusy | ( | tMUXmotor | muxmotor, |
ubyte | address | ||
) |
Check if the specified motor is running or not.
muxmotor | the motor-MUX motor |
address | I2C address of the sensor (optional) |
Definition at line 479 of file mindsensors-motormux.h.
long MSMMotorEncoder | ( | tMUXmotor | muxmotor, |
ubyte | address | ||
) |
Fetch the current encoder value for specified motor channel
muxmotor | the motor-MUX motor |
address | I2C address of the sensor (optional) |
Definition at line 415 of file mindsensors-motormux.h.
bool MSMMotorEncoderReset | ( | tMUXmotor | muxmotor, |
ubyte | address | ||
) |
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 |
address | I2C address of the sensor (optional) |
Definition at line 448 of file mindsensors-motormux.h.
bool MSMMotorEncoderResetAll | ( | tSensors | link, |
ubyte | address | ||
) |
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 |
address | I2C address of the sensor (optional) |
Definition at line 467 of file mindsensors-motormux.h.
void MSMMotorSetBrake | ( | tMUXmotor | muxmotor ) |
Set the stopping method for the specified motor to brake.
muxmotor | the motor-MUX motor |
Definition at line 534 of file mindsensors-motormux.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 386 of file mindsensors-motormux.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 401 of file mindsensors-motormux.h.
void MSMMotorSetFloat | ( | tMUXmotor | muxmotor ) |
Set the stopping method for the specified motor to float.
muxmotor | the motor-MUX motor |
Definition at line 544 of file mindsensors-motormux.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 566 of file mindsensors-motormux.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 359 of file mindsensors-motormux.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 555 of file mindsensors-motormux.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 373 of file mindsensors-motormux.h.
bool MSMMotorStalled | ( | tMUXmotor | muxmotor, |
ubyte | address | ||
) |
Check if the specified motor is running or not.
muxmotor | the motor-MUX motor |
address | I2C address of the sensor (optional) |
Definition at line 520 of file mindsensors-motormux.h.
void MSMMUXinit | ( | ) |
Definition at line 145 of file mindsensors-motormux.h.
bool MSMMUXreadStatus | ( | tMUXmotor | muxmotor, |
ubyte & | motorStatus | ||
) |
bool MSMMUXreadStatus | ( | tMUXmotor | muxmotor, |
ubyte & | motorStatus, | ||
ubyte | address | ||
) |
Read the status byte of the specified motor
muxmotor | the motor-MUX motor |
motorStatus | status of the motor |
address | I2C address of the sensor (optional) |
Definition at line 166 of file mindsensors-motormux.h.
bool MSMMUXsendCommand | ( | tSensors | link, |
ubyte | command, | ||
ubyte | address | ||
) |
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 |
address | I2C address of the sensor (optional) |
Definition at line 233 of file mindsensors-motormux.h.
bool MSMMUXsendCommand | ( | tSensors | link, |
ubyte | channel, | ||
long | setpoint, | ||
byte | speed, | ||
ubyte | seconds, | ||
ubyte | commandA, | ||
ubyte | address | ||
) |
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 |
address | I2C address of the sensor (optional) |
Definition at line 200 of file mindsensors-motormux.h.
bool MSMMUXsetPID | ( | tSensors | link, |
unsigned int | kpTacho, | ||
unsigned int | kiTacho, | ||
unsigned int | kdTacho, | ||
unsigned int | kpSpeed, | ||
unsigned int | kiSpeed, | ||
unsigned int | kdSpeed, | ||
ubyte | passCount, | ||
ubyte | tolerance, | ||
ubyte | address | ||
) |
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 |
address | I2C address of the sensor (optional) |
Definition at line 266 of file mindsensors-motormux.h.
bool MSMotorStop | ( | tMUXmotor | muxmotor, |
ubyte | address | ||
) |
Stop the motor. Uses the brake method specified with MSMMotorSetBrake or MSMMotorSetFloat. The default is to use braking.
muxmotor | the motor-MUX motor |
address | I2C address of the sensor (optional) |
Definition at line 326 of file mindsensors-motormux.h.
bool MSMotorStop | ( | tMUXmotor | muxmotor, |
bool | brake, | ||
ubyte | address | ||
) |
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 |
address | I2C address of the sensor (optional) |
Definition at line 343 of file mindsensors-motormux.h.
Array to hold I2C reply data
Definition at line 115 of file mindsensors-motormux.h.
Array to hold I2C command data
Definition at line 114 of file mindsensors-motormux.h.