LabVIEW

Programming the MATRIX controller with LabVIEW for LEGO MINDSTROMS 

The MATRIX LABView Palette contains the following VIs:

Notes on using the MATRIX VIs

All the MARIX VIs have an input called Port which is the NXT sensor port used to connect to the MATRIX controller.  The default value for this input is Port  4.  If you connect your MATRIX controller to this port then you will not need to wire the Port input when using the VIs.  The sample programs here assume that MATRIX controller is connected to the default port 4 so the port input is not wired.

The MATRIX VIs can be used in either direct mode in a program that is targeted to your PC or they can be targeted to run natively on the NXT.  This makes it possible to easily test and debug VIs before deploying them to run on the NXT.

Controller Timeout (and feeding the Watchdog)

The MATRIX controller has a timeout functionality called a watch dog to prevent run away robots.  If your program has pauses longer than two seconds between MATRIX interactions, then the controller will timeout and disable the motors and servos.  To prevent this from happening, you will need to implement a watchdog feeder in your program.  See the sample program for Feed Watchdog for an example on how to this.

Motor Direction

The normal direction for a MATRIX Motor is clockwise.  If you use the motors to directly drive the wheels on your robot then the right motor will go in the normal forward direction while the left motor will normally go in reverse.  To correct this the Motor inputs on the MATRIX Motor, Motor Status, and Move VIs lets you select either the normal direction for the motor; Motor 1, Motor 2, Motor 3, or Motor 4; or the inverted direction for the motor;  Inv. Motor 1, Inv. Motor 2, Inv. Motor 3, or Inv. Motor 4.  For example, when you expand the Motor constant it will look like this:

Note that the Move VI is specially designed to let you control the drive motors of a robot and controls two motors.  This VI uses a cluster for its Motor input that contains the left and right motors.  The default value for this cluster is Inv. Motor 3 for the left motor and  Motor 1 for the right motor.

Check Battery [MATRIX Check Battery.vi]

Reads the battery voltage of the battery pack attached to the Matrix controller.  This VI also outputs the NXT battery level.

Inputs

  • NXT  connects to NXT terminal of previous VI to establish the flow of the program.
  • Port  is the port used for the MATRIX controller.

Outputs

  • NXT  wires to NXT terminal of next VI to establish the flow of the program.
  • NXT Voltage  is the voltage level of the batteries in the NXT.
  • Controller Voltage  is the voltage level of the battery pack connected to the controller.

The Check Battery VI lets you read the battery level of the external battery pack as well as the NXT battery level.  Here is a sample program that displays the battery levels on the NXT screen:

Feed Watchdog [MATRIX Feed Watchdog.vi]

The MATRIX controller watchdog will automatically shutdown motors and servos if there is no interaction from the NXT for 2 seconds (default timeout setting).  To keep the MATRIX controller active beyond 2 seconds, use this VI to feed the watchdog.

Inputs

  • NXT  connects to NXT terminal of previous VI to establish the flow of the program.
  • Port  is the port used for the MATRIX controller.

Outputs

  • NXT  wires to NXT terminal of next VI to establish the flow of the program.

In this sample program, the MATRIX Move vi is used to drive the robot until a touch sensor is pressed, and then stop.   Since this can take longer than two seconds, it is necessary  to have a watchdog feeder in order to keep the motors running.

The Watchdog feeder loop in this sample uses a Boolean control to signal when the program is done.  After the touch sensor has been pressed and the motors are stopped, the stop control is set to True which makes the watchdog feeder loop exit.

Motor Status [MATRIX Motor Status.vi]

Gets the encoder position and busy state of a MATRIX motor.  Note that the Motor input allows you to indicate that the motor direction is inverted.  MATRIX Motor encoder values are in encoder ticks which are approximately 751.8 per rotation.

Inputs

  • NXT  connects to NXT terminal of previous VI to establish the flow of the program.
  • Port  is the port used for the MATRIX controller.
  • Motor  Motor 1 to Motor 4.  To invert direction of motor use Inv. Motor.

Outputs

  • NXT  wires to NXT terminal of next VI to establish the flow of the program.
  • Busy  is true if motor is currently doing Slew to position and has not yet reached the target.
  • Position  is the  current motor encoder position.

This VI can be used to read the motor encoders that are integrated with the MATRIX motors.  It can also be used to determine if a motor is busy doing a Slew to Position action.  Note that the MATRIX Motor encoders have 751.8 encoder ticks per rotation (2.088 degrees per tick).  This program will display the encoder position of Motor 1 on the NXT screen in ticks, degrees, and rotations:

Motor [MATRIX Motor.vi]

Operate a motor on the MATRIX controller.  Note that the Motor input allows you to invert the direction of the motor.  When using Power or Speed control, use a negative value for Speed/Power to make the motor go in reverse.  For Slew to position, the motor direction is determined by the direction to the target.  A Speed/Power value of 0 will stop the motor.  If you want to synchronize the action of multiple motors, then Set Pending should be True and then Start Pending should be used to active the motors.

Inputs

  • NXT  connects to NXT terminal of previous VI to establish the flow of the program.
  • Port is the port used for the MATRIX controller.
  • Motor  Motor 1 to 4.  To invert direction of motor use Inv. Motor 1 to 4.
  • Mode/Action specifies one of four modes or a Reset action.
    • Power 0 float – control power to motor using float for power 0.
    • Power 0 brake – control power to motor using brake for power 0.
    • Speed control – control the speed of the motor.
    • Slew to position – control speed and drive motor to the specified target position.
    • Reset – reset the motor.  Stops the motor, sets encoder to 0.
  • Speed/Power a value from -100 to 100.  (0 to 100 for Slew to position)
  • Target Position target encoder position for Slew to position.
  • Set Pending delay start of action until the Start Pending command is issued.  Use to synchronize the action of multiple motors.

Outputs

  • NXT  wires to NXT terminal of next VI to establish the flow of the program.

This VIs supports several different motor modes.

  • Power 0 float and Power 0 brake, are considered open loop and are unregulated.  The actual motor speed for a given power level will depend not only on the power value but also on the load placed on the motor.  The difference between these modes is how the motors behave when the power level is 0.  Brake indicates that the motor rotation is impeded while float means the motor can turn freely.
  • In Speed control mode, the controller actively attempts to maintain a constant speed with the motor.  In this mode the Speed/Power input is a speed setting.  This is considered closed loop since the encoder feedback is used to regulate the motor.
  • Use Slew to position to drive the motor toward a specific encoder position specified by the Target Position input.  This mode also regulates the motor speed.
  • Reset will reset the motor encoder and stop the motor.

Use the Set Pending option to synchronize multiple motors.  When this flag is True, the action is not immediate and does take effect until the Start Pending vi is used.

Here is sample of the Slew to Position action to drive motor 1 toward the encoder position 752 and then back to 0.

Note the WaitFor Motor Not Busy is used to check if motor has reached its target position.

Move Servo [MATRIX Move Servo.vi]

Turn the MATRIX servo horn to a specified position.

Note: The target value can potentially attempt to move a servo beyond its internal mechanical limits. When operating at <50 or >205, listen to the servo and ensure that it is not continually trying to go beyond its internal mechanical limit. This may overheat and damage the servo as well as waste battery power.

Inputs

  • NXT  connects to NXT terminal of previous VI to establish the flow of the program.
  • Port  is the port used for the MATRIX controller.
  • Servo  specifies which servo, Servo 1 to 4, to operate.
  • Target  the target position of the servo is a value from 0 to 255.
  • Speed Delay  allows the rotation rate of the servo to be controlled.  At zero the change to the servo position is immediate. If the value is non-zero, change will occur at a rate is Speed Delay * 10 milliseconds per step.

Outputs

  • NXT  wires to NXT terminal of next VI to establish the flow of the program.

Use this VI to control the position of a MATRIX Servo.    Make sure the servo being controlled bas been enabled using the Servo Enable VI.  Speed Delay can be used to slow down the servo.   Internally the controller pans the target at a rate determined by this value.  At 0, the change in target position is immediate.

This sample program uses an NXT motor as a rotation sensor to set the servo target position.  Turn the NXT motor on Port A and the servo 1 will match the position.

Note that Servo Enable must be used to active the servos you want to control.

Servo Enable [MATRIX Servo Enable.vi]

Enable or disable servos connected to the MATRIX controller.

Inputs

  • NXT  connects to NXT terminal of previous VI to establish the flow of the program.
  • Servos  specifies which servos to enable.  Numerically this is a binary value with one bit per servo.  For example, to enable servos 1 and 2 then the value should be 3.  To enable all servos, then use 15.  Servos constant lets you select servo combination from a list.

Outputs

  • NXT  wires to NXT terminal of next VI to establish the flow of the program.

The Servos constant is a bitmap value with one bit per servo.  When you create a constant for this input you can select any combination of servos from a list.  For example, in this sample program servos 1 and 2 have been enabled and are then controlled by the X and Y axis of a HiTechnic Acceleration sensor:

Start Pending [MATRIX Start Pending.vi]

Start action on all motors with the Set Pending flag set.  To synchronize multiple motors on the controller, set the desired action with the Set Pending flag.  Then use this VI to start all pending motors.

Inputs

  • NXT  connects to NXT terminal of previous VI to establish the flow of the program.
  • Port is the port used for the MATRIX controller.

Outputs

  • NXT  wires to NXT terminal of next VI to establish the flow of the program.

If you  start motors with the MATRIX Motor VI without synchronizing them, then there is a short time after the first motor starts before the second motor starts (about 10ms).  To ensure that the motors start together, you can use the Set Pending option on the Motor VI and then Start Pending to start the motors together.  In this sample both motors are started together and then they are stopped together one second later.

Move [Matrix Move.vi]

Control to Matrix Motors to drive a robot.  Specify the Matrix controller port and the motors used to drive the robot.  Use a negative Speed value to make the robot drive in reverse.

The default for Motors is Left Motor = Inv. Motor 3 and Right Motor = Motor 1.

The Steering Angle determines how much the robot steers while driving.  This value is in degrees and is in the range of -90 to 90.  Imagine the robot as a tricycle with the wheels laid out as an equilateral triangle with a front steerable wheel.  If the steering angle is 0 then the robot drives straight.  If you turn the steering wheel 60 degrees to the right then the robot will pivot around the stopped right wheel.  If you set the steering angle to 90 then the robot will spin in place with the right wheel going in reverse while the left wheel going forward.  To steer to the left use a negative steering angle.

Inputs

  • NXT  connects to NXT terminal of previous VI to establish the flow of the program.
  • Port  is the port used for the MATRIX controller.
  • Motors  is a cluster that contains the left and right motors ports used.  Note that if a motor should be reversed then specify the motor using the inverted selection.
  • Speed  Is the motor speed as a value from -100 to 100.  Use a negative value to make the robot drive in reverse.
  • Steering Angle (deg)  This value controls how the robot should steer.

Outputs

  • NXT  wires to NXT terminal of next VI to establish the flow of the program.

The Steering Angle input has a physical correlation to how the robot steers while driving.  To understand the meaning of this value, imagine the robot has steerable wheel in front, like a tricycle, with the three wheels making an equilateral triangle.  When this wheel is at 0 degrees, the robot will drive straight with both left and right motors turning the same speed.  If the steering angle is turned 30 degrees left or right, then the effective speed of the inside wheel will be half of that of the outside wheel.  In this case the turning radius will be 1 1/2 of the wheelbase of the robot.  If the steering angle is 60 degrees, then the imaginary wheel is perpendicular to the inside of the triangle, thus the inside wheel will be stopped and all the driving speed will go to outside wheel.  If you turn the steering all the way to 90, then the robot will turn in place with the inside wheel going in the opposite direction of the outside wheel.

This sample program will make the MATRIX Rover go in a square pattern.

The WaitFor Motors Change VIs are a convenient way to monitor the change in motor encoder values.  The first WaitFor waits for the sum of the two motor encoders to change by 4000 ticks (about 5 wheel rotations).  The second WaitFor waits for the difference of the encoders to change by 780 ticks.  This difference is calculated left minus right so the change is positive.  If it was steering left the change would be negative.  Since this WaitFor is monitoring the difference in encoders, changing the Steering Angle should not change the amount that the robot turns.  This turn will close to a 90 degree turn regardless of the steering angle.

adidas yeezy boost v3 shoe adidas yeezy boost v2 shoes adidas yeezy boost 350 v3 shoe adidas yeezy boost 350 v2 shoes adidas yeezy boost 350 v2 black red adidas yeezy boost 350 v2 black white adidas yeezy boost 350 v2 triple white adidas yeezy boost 350 v2 cream white adidas yeezy boost 350 v2 black adidas yeezy boost 350 v3 grey adidas yeezy boost 350 v3 yellow