Lab Objectives:
- Use Matlab and Labjack to acquire digital inputs from limit switches
- Use Matlab and Labjack to control a stepper motor
- Use Matlab to analyze acquired data
- Use a simple control system to vary an output based upon input data
- Set-up and Basic Control of the XY Tables
Lab Equipment Required
- Laptop with Matlab/Labjack software installed
- Labjack DAQ with USB cable
- DB25 cable for interfacing with the XY table
- XY table
- Power supply
- Two power lead wires
- Ruler
Equipment Set Up
The XY tables are pre-wired to interface with the Labjack DAQ units using the DB25 cable. However, attention must be paid to the channels used for each of the inputs and outputs while writing the program. Special care must be given to distinguish between digital input and digital output signal types. It is possible to damage the equipment if these are reversed (i.e. writing an output to a closed switch input).
The axes and limit switch locations are shown in the Figure below.
Notice that A refers to "Away" from the end with the motor, and B refers to "By" the motor.
The table below contains the wiring assignments for the Labjack IO connections. These cannot be changed since they are hard-wired from the circuit to the motors and from the XY tables to the Labjack connector.
The important channels for this lab are:
X-axis: direction commands (channel D1) - outputs, EDigitalOut()
step commands (channel D0) - outputs, EDigitalOut()
limit switch signal (channels D8 and D9) - inputs, EDigitalIn()
Y-axis: direction commands (channel D5) - outputs, EDigitalOut()
step commands (channel D4) - outputs, EDigitalOut()
limit switch signal (channels D10 and D11) - inputs, EDigitalIn()
Direction of MOTOR rotation --- controlled by setting state of channel D1 HIGH or LOW. If D1 is LOW, the default, the bearing block moves in the plus x direction (towards end A). The X-axis motor will rotate one step (0.9 degrees) each time a pulse (a HIGH signal followed by a LOW) is sent to channel D0.
Example: EDigitalOut (-1, 0, 1, 1, 0) % ch D1 sets direction to plus x direction (state = 0).
EDigitalOut (-1, 0, 0, 1, 1) % ch D0 step high pulse (state = 1).
EDigitalOut (-1, 0, 0, 1, 0) % ch D0 step low pulse (state = 0).
Several other connections may be of interest in future labs and as the last two weeks will be spent designing an individually developed system. D2 and D6, when turned on (HIGH) will cause the respective stepper motors to run in a ½ step mode. These motors turn 0.9 degrees per step, therefore the ½ step mode will produce only 0.45 degrees per step. This doubles the X and Y resolution as each pulse only travels ½ of the default distance. Notice that the steps per second (commanded from the computer) do not change and thus it also takes twice as long to move the same distance. Note that each motor may be remotely disabled by setting the outputs D12 and/or D13 to HIGH.
Programming for the XY Tables
1. Set-up and test the XY Table
Connect the hardware as described in the previous section. Next, open the Labjack LJLogger application and use it to verify that everything is connected and working properly. In particular, and with the main power supply off, move (by hand) the bearing slides to the various endpoints. When each respective limit switch is contacted, the LJLogger screen should light up the respective input button.
Verify the function of all four of the limit switches (channels D8, D9, D10, D11). Finally, set channels D0, D1, D4, and D5 directions to Write and turn on the main power supply; now when the various outputs are toggled between HIGH and LOW the corresponding motor should single step in direction selected. When finished, turn the main power supply back to OFF, as leaving this on while not in use generates significant heat in the four power resistors located under the main driver circuit board.
2. Move 100 Steps Along the X-axis
Write a simple MATLAB program to move the X axis 100 steps towards end A, followed by moving it back towards end B with another 100 steps. Think about different ways that this can be accomplished using loops. Before running this program, move the bearing slide on the X-axis far enough away from end A so that the limit-switch is not contacted. Write a flowchart for this part in your three ring binder.
3. Measure X-axis Travel Distance, and Find and Move to the Center of the X-axis
Now combine the limit switch feedback with the ability to move the X-axis motor. Write a MATLAB program to perform the following steps:
a. Move the X-axis carrier towards switch A until the limit switch is actuated. Pause the program. Make a pencil mark on the stationary axle being traversed. Continue.
b. Create a STEPS variable and move the X-axis carrier towards switch B until the next limit switch is actuated. Use a WHILE loop to continually increment steps until finished so that when switch B is contacted the number of steps that it took to travel from limit switch A to limit switch B on the X-axis will have been stored. Display the number of steps on the screen. Pause the program. Make a pencil mark on the stationary axle being traversed. Continue.
c. Finally, move the X-axis carrier to its center position (STEPS/2), and end the program. Use a FOR loop instead of a WHILE loop.
d. Measure the distance between your two pencil marks with the ruler. Fill out the worksheet for the x-axis calculations.
4. Measure Y-axis Travel Distance, and Find and Move to the Center of the Y-axis
Repeat part 3, steps a, b, c, and d for the Y-axis. Consider how easy it is to take the existing code from part 3, copy it in a new program, change several IO variables, and repeat the procedure for the Y-axis.