Motor Control with DSP Motor Control Block Select
Motor Control with DSP
Motor Control Block • Select from Motor Module • 4 channels are available. Create a constant for the channel • Electronic speed control takes an input from -1 to 1. Create a control for the speed. Make it a slider on the front panel. • A simple while loop will work for your first motor controller. (see next slide)
A simple motor speed controller. The SPEEDY-33 motor controller can control up to 5 amps. This will not allow you to control very big motors.
Problems with motor control • Timing – Just like with servo control, timing commands do not seem to work very well because the PWM signal is tied into the timing circuitry of Lab. VIEW. – Solve this problem by timing the length of the motor run by counting through a bunch of FOR Loops. – The counting is not as consistent as timing, but with some care and patience you can get it to work pretty well. • Problem: Get a motor to turn on for 3 seconds, off for 2 seconds. Repeating the pattern indefinitely.
One Solution is the following This has a For LOOP counting up to a number. Inside of a Sequence Structure with two sequences. One frame has the motor on, the second frame has the motor off. This is all inside of a while loop so the program runs continuously (more details on next slide)
Variable Timing Control The counting is controlled by one Controller that sets a high number that will be the ticks per second. This is not always going to be the same. It will change on different computers and in different programs. This gets multiplied by the number of seconds for each sequence frame.
The ticks per second will be a fairly high number. Try 50000 to start. Making this a numeric control that can be easily changed will help you find the correct value.
The “Motor ON” Frame Motor On for 3 seconds. Hint: Watch the lights, not the motor, because of momentum it spins more than 3 seconds. Or put a boolean indicator that goes on and off with the motor and watch it.
The “Motor OFF” Frame Motor Off for 2 seconds.
Timing Assignment • Play with this for a while and tell me how many ticks are needed for one second. • Make a motor controller that goes on for 3 seconds and off for 2 seconds. Have it repeat within a while loop so the action is repeated until stopped. • For extra credit, make a simple boolean indicator that shows when the motor is on and off.
More problems with motor control • Acceleration – If you would try to turn the motor on and off in different directions at full power, you could put some very large torque into your whole system. This could damage the motor or the parts of the robot that the motor is attached to. – Solve this problem by “ramping up” the speed of the motor as a For Loop counts.
Ramp Up to Speed • The following will ramp up to speed as i counts from 0 to 200, 000. The speed goes from 0 to 1 because of the simple division.
Ramp Down from full speed • The following will ramp down from full speed to zero. • The speed is 1 i/200, 000 as i counts from 0 to 200, 000. • Be careful to wire this correctly.
Ramping Assignment • Make a vi that will ramp up to full speed, run at full speed for a while, then ramp down to speed zero. (Part 1) • Modify this to ramp up to full speed, run for a while, ramp from full speed forward to full speed reverse, run for a while, then ramp back to speed zero. (Part 2) • For extra credit, put some boolean indicators on the Front Panel to indicate what is going on: ramp up, forward, reverse, ramp down. • You can do this with either a sequence structure or a case structure operating inside a For-Loop.
Count to keep track of Position • Instead of using rather crude timing commands to keep track of where a robot is located, it is more precise to connect a switch to the wheels and count each time the wheel hits the switch. • The resolution of this can be increased by gearing the connection to the switch so that many pulses are received for a single revolution of the wheel. • In practice, this technique is implemented using devices called shaft encoders. There are some websites that show to put a encoder onto a servo motor.
Counting on the DSP • When using motor control, there are four inputs that can be used to count. Because of other considerations with the R/C receiver, you should use Lines 4, 5, 6 & 7 for the digital inputs. These are actually the last 4 switches because numbering starts with 0. • The switches are easy to start with for testing, later on you will need to wire an external switch to one of the inputs on J 5. • These inputs are on the J 5 connector at pins 11, 13, 15 & 17. Pin 19 is ground.
Counting on the DSP • Start simple • Make sure you can see the switch 8 go on and off • Build the vi as shown, the boolean indicator should go on and off with the switch 8 (or input 7 if you start numbering at 0)
Counting on the DSP • When you run this vi, toggle switch 8 on and off to make sure this is working.
Counting on the DSP • Right click on the right edge of the WHILE LOOP to create a shift register. • This carries a previous value around the loop to the left side
Counting on the DSP • Wire the switch output to the right shift register. • Create a constant on the left shift register that will have the value of FALSE. • These two values will loop around with a false value until the switch goes on. Then for an instant, the left register is FALSE but the right register is TRUE.
Counting on the DSP • So when the switch goes on, the two registers are different for only one interation of the loop. • Now the loops registers will both be running around with TRUES. • There is a logical device that reads when two things are different: called an EXCLUSIVE OR. Right Click and go into the Boolean devices to select the Exclusive Or.
Counting on the DSP • Wire the switch and the left shift register into the EXCLUSIVE OR. • Create an indicator to see when the EXLUSIVE OR fires to TRUE. • It will be too fast to see unless you slow the loop down with some timing delays. • Run this to make sure it works.
Counting on the DSP • Notice that the Exclusive Or goes to True when the switch is both “Made” and when it is “Broken. ” • Be sure to think through why this is happening.
Counting on the DSP • Right click to create another shift register. • Create a numeric constant of “ 0” and wire to the left shift register. • Find the +1 increment block and wire it to the top of a Select Block. • Complete the rest of the wires.
Counting on the DSP • A bunch of “zeros” start looping around through the shift registers. • When the switch makes the • ‘EXCLUSIVE OR” go TRUE, it sends a +1 into the loop. • This makes the looping values equal to 1. • Another switch change puts another +1 into the loop making it 2.
Counting on the DSP • Add a numerical display to see this counting value increase when you run the program and toggle the switch. • This value is actually twice the number of actual switch hits, but you could easily adjust this. • The 500 ms delay might make this miss some counts, reduce the time for better accuracy.
Counting on the DSP • But a time that is too little can also cause trouble because of “bouncy” switches. • You will get some unwanted counts sometimes. • You should remove the timing delay because it causes errors with motor control (coming next)
Wiring an external switch Instead of using the switches on the front of the SPEEDY-33, you can wire into the J 5 between pin 19, ground, and other pins for the 8 switches. Because of other uses of these outputs with motor control, there are only 4 available switches.
Pin Arrangement on Speedy-33 • • You should see the label for pin 1 The other pins are as follows. You can use pins 11, 13, 15 & 17 going to pin 19 (ground) These correspond to switches 5, 6, 7 & 8. 1 3 5 7 9 11 13 15 17 19 Connect wires onto pins 17 and 19 to use switch 7 (really 8).
Lego Motor and Switch A good switch to use is a little sensor switch that is part of the Lego system. Connect a motor, a cam and a switch so that a rotating motor rotates the cam to close the switch. Connect the switch into the J 5 connector.
Motor control with counting • The next (and almost last) thing to do is to make the motor run for a certain number of counts and then shut it off. • This can be expanded by putting a number of counting into a SEQUENCE structure and then work through the steps to make the robot move where it is supposed to.
Motor control with counting • Replace the slider with a fixed speed (maybe 1 would be better than this number) • Have the alternative speed be “ 0” going through a Select Block • This runs as long as the count value is below a certain threshold.
Motor control with counting • Build a comparison block to check to be sure the count is below a threshold (we’ll set it at 30) • Now the speed will be. 2727 until 30 counts, then it goes to zero. • Works Well, right?
Wire for a Stoppage • The last thing to do is to wire the count comparison into the LOOP so it stops. Easy to do but you have to change the type of stop control to CONTINUE if TRUE instead of STOP when TRUE.
Sequence the Counter • Now put the whole counter into a sequece. • Duplicate the frames and change the counter values and the speeds. • You may want to remove the Boolean displays now that you know it is working. This will reduce the amount of clutter on the main screen. • Next slide shows an example of forward 30, back 20, and forward 10.
Frame 0 Frame 1 Frame 2
Motor control with counting. Make sure that the switch is doing the counting on the SPEEDY-33. Be sure the physical switch 8 is turned off, or the Lego Switch won’t work. Add a motor control block to the program so that the motor spins and rotations are counted. Of course you are really counting double rotations.
- Slides: 37