Mindstorms 3rd Party ROBOTC Drivers RobotC
[Home] [Download] [Submit a bug/suggestion] [ROBOTC Forums] [Blog] [Support this project]
Files | Defines | Functions | Variables

NXT Motor MUX
[Mindsensors]

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

Detailed Description

NXT Motor MUX


Define Documentation

#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.


Function Documentation

bool MSMMotor ( tMUXmotor  muxmotor,
byte  power,
ubyte  address 
)

Run motor with specified speed.

Parameters:
muxmotorthe motor-MUX motor
powerpower the amount of power to apply to the motor, value between -100 and +100
addressI2C address of the sensor (optional)
Returns:
true if no error occured, false if it did
Examples:
mindsensors-motormux-test1.c, and mindsensors-motormux-test2.c.

Definition at line 299 of file mindsensors-motormux.h.

bool MSMMotorBusy ( tMUXmotor  muxmotor,
ubyte  address 
)

Check if the specified motor is running or not.

Parameters:
muxmotorthe motor-MUX motor
addressI2C address of the sensor (optional)
Returns:
true if the motor is still running, false if it's idle
Examples:
mindsensors-motormux-test1.c.

Definition at line 479 of file mindsensors-motormux.h.

long MSMMotorEncoder ( tMUXmotor  muxmotor,
ubyte  address 
)

Fetch the current encoder value for specified motor channel

Parameters:
muxmotorthe motor-MUX motor
addressI2C address of the sensor (optional)
Returns:
the current value of the encoder
Examples:
mindsensors-motormux-test1.c, and mindsensors-motormux-test2.c.

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.

Parameters:
muxmotorthe motor-MUX motor
addressI2C address of the sensor (optional)
Returns:
true if no error occured, false if it did
Examples:
mindsensors-motormux-test1.c.

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.

Parameters:
linkthe MMUX port number
addressI2C address of the sensor (optional)
Returns:
true if no error occured, false if it did
Examples:
mindsensors-motormux-test1.c, and mindsensors-motormux-test2.c.

Definition at line 467 of file mindsensors-motormux.h.

void MSMMotorSetBrake ( tMUXmotor  muxmotor )

Set the stopping method for the specified motor to brake.

Parameters:
muxmotorthe motor-MUX motor
Examples:
mindsensors-motormux-test1.c.

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.

Parameters:
muxmotorthe motor-MUX motor
targetthe encoder target value in degrees.
Returns:
true if no error occured, false if it did
Examples:
mindsensors-motormux-test1.c.

Definition at line 386 of file mindsensors-motormux.h.

void MSMMotorSetEncoderTarget ( tMUXmotor  muxmotor,
long  target,
bool  relative 
)

Set encoder target for specified mux motor.

Parameters:
muxmotorthe motor-MUX motor
targetthe encoder target value in degrees.
relativespecified target is relative to current position.
Returns:
true if no error occured, false if it did

Definition at line 401 of file mindsensors-motormux.h.

void MSMMotorSetFloat ( tMUXmotor  muxmotor )

Set the stopping method for the specified motor to float.

Parameters:
muxmotorthe 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.

Parameters:
muxmotorthe motor-MUX motor
rampinguse 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.

Parameters:
muxmotorthe motor-MUX motor
targetthe rotation target value
Returns:
true if no error occured, false if it did

Definition at line 359 of file mindsensors-motormux.h.

void MSMMotorSetSpeedCtrl ( tMUXmotor  muxmotor,
bool  constspeed 
)

Set the motor speed control for the specified motor.

Parameters:
muxmotorthe motor-MUX motor
constspeeduse 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.

Parameters:
muxmotorthe motor-MUX motor
targetthe time target value in seconds [1-255]
Returns:
true if no error occured, false if it did
Examples:
mindsensors-motormux-test1.c.

Definition at line 373 of file mindsensors-motormux.h.

bool MSMMotorStalled ( tMUXmotor  muxmotor,
ubyte  address 
)

Check if the specified motor is running or not.

Parameters:
muxmotorthe motor-MUX motor
addressI2C address of the sensor (optional)
Returns:
true if the motor is still running, false if it's idle

Definition at line 520 of file mindsensors-motormux.h.

void MSMMUXinit (  )
bool MSMMUXreadStatus ( tMUXmotor  muxmotor,
ubyte &  motorStatus 
)
bool MSMMUXreadStatus ( tMUXmotor  muxmotor,
ubyte &  motorStatus,
ubyte  address 
)

Read the status byte of the specified motor

Parameters:
muxmotorthe motor-MUX motor
motorStatusstatus of the motor
addressI2C address of the sensor (optional)
Returns:
true if no error occured, false if it did

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

Parameters:
linkthe MMUX port number
commandthe command to be sent to the motor
addressI2C address of the sensor (optional)
Returns:
true if no error occured, false if it did

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

Parameters:
linkthe MMUX port number
channelthe channel the command should apply to
setpointthe encoder count the motor should move to
speedthe speed the motor should move at
secondsthe number of seconds the motor should run for. Note that this takes precedence over the encoder target
commandAthe command to be sent to the motor
addressI2C address of the sensor (optional)
Returns:
true if no error occured, false if it did

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.

Parameters:
linkthe MMUX port number
kpTachoKp for Tachometer Position Control
kiTachoKi for Tachometer Position Control
kdTachoKd for Tachometer Position Control
kpSpeedKp for Speed Control
kiSpeedKi for Speed Control
kdSpeedKd for Speed Control
passCountEncoder count tolerance when motor is moving
toleranceEncoder count tolerance when motor is getting close to target
addressI2C address of the sensor (optional)
Returns:
true if no error occured, false if it did
Examples:
mindsensors-motormux-test1.c.

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.

Parameters:
muxmotorthe motor-MUX motor
addressI2C address of the sensor (optional)
Returns:
true if no error occured, false if it did
Examples:
mindsensors-motormux-test1.c, and mindsensors-motormux-test2.c.

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.

Parameters:
muxmotorthe motor-MUX motor
brakewhen set to true: use brake, false: use float
addressI2C address of the sensor (optional)
Returns:
true if no error occured, false if it did

Definition at line 343 of file mindsensors-motormux.h.


Variable Documentation

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.