PMAC+-+Practicum+4de+orde

=1 Introduction PMAC and workshop= A PMAC you can use for motion control. Because of the simple architecture it is very easy to start setting up a control loop, or even multiple parallel loops. For more information about the PMAC see documentation (this link provides several .pdf's as background information. More to find on this page is the congifuraion settings for the 4-axes robotarm set-up.) This workshop has been used for the minor "Mechatronics". The students learn how to control a 4th-order-system (mass - spring - mass, with on both masses a encoder) using an industrial motion controller as the PMAC. Some terms of interest are: PID and parallelization.

In chapter 2 you will find information how you can setup the system, and how different windows of the PC program can be used. The chapters 3 - 6 describe the activities of the four weeks.

=2 System setup= You need a PMAC, a 4th-order system and a PC. Ask the lab assistent if they are connected well. On the PC, you have to startup the program **Pewin32PRO** (present at the Desktop). The first action to do is to restore a configuration via the menu: Backup -> Restore Configuration -> select "pmac2.ini" (you can find it on the desktop) **Not**
 * necessarily!**

In this workshop you will work with the following windows:
 * //terminal// to give direct commands to the PMAC
 * //editor// to write and download PMAC programs
 * //watch// to view internal data of the PMAC
 * //position// to see the actual position and velocity of the motor

A short description of those windows is given below:

2.1 Terminal window
Start a //terminal// window via View.

The following commands will be used: (See also "PMAC AND PMAC 2 Software.pdf", chapter PMAC ON-LINE COMMAND SPECIFICATION on page 166) code format="matlab" VERSION % check if the PMAC operates $ % reset the motor, and set the motor in closed-loop k % set the motor in open-loop b1r % run motion program 1 (today, we'll have only one program) a % abort a program enable plc 5 % start a plc program disable plc 5 % stop a plc program list prog 1 list plc 2 % (for verification) give the contents of a motion or a plc program hmz % set the motor position back to zero ^D % (ctrl-D) disable all programs code

2.2 editor
You can create a new file via File -> New File. A PLC program has the following layout (PLC 13 is taken as an example): code format="matlab" close open plc 13 clear



close enable plc 13 code The last line immediately starts the PLC program (this is not necessary: you can also start (and stop) it via the //terminal// window).

A Motion program has the following layout: code format="matlab" close open prog 1 clear

linear abs



close code

Download your program to the PMAC via the button with the yellow arrow. You will be warned if there are errors in your program. They have to be corrected.

See also "PMAC_UserManual.pdf", sections:
 * Entering a Motion Program (page 198)
 * Writing a PLC Program (page 233)

2.3 watch window
To add a new variable and to delete a variable: use the right mouse button

2.4 plotting on the screen
When a motion program or a plc program runs, the PMAC can collect the data of various items. They can be uploaded to the PC and viewed in a plot with the program PMACPlot32PRO2 (startup via Tools). This is convenient for observing the position, velocity and acceleration of a motor (see week 3 and 4)
 * "add to left" / "add to right" select and deselect items to gather
 * "define gathering buffer" has to be given before a new gathering
 * "begin gathering" start data collection
 * "end gathering" stop data collection
 * "upload data" & "plot data" upload data to the PC and make the plot

Interesting items are: Note: in Mtr 1 Act Accel you will see that notice that there is a lot of control to keep the required velocity
 * Mtr 1 Act Pos/Vel/ Accel actual position/velocity/acceleration
 * Mtr 1 Cmd Vel/Pos/Accel commanded (required) position/velocity/acceleration

=3 Week 1=

3.1 My first PLC program
code format="matlab" close open plc 1 clear
 * turn on the PMAC
 * start Pewin32PRO
 * check if it is operational with command VERSION in the //terminal// window.
 * create a new PLC program via File -> New File -> plc1.pmc, with the contents:

P10=P10+1

close enable plc 1 code
 * download it to the PMAC
 * add a watch for P10 in the //watch// window

NOTE: As the PMAC doesn't have other activities to do, P10 increments very fast.


 * create a new file (File -> New File -> plc2.pmc) for a new PLC program for PLC 2, the contents must be similar to PLC 1
 * it has the statement: increment variable P20
 * add a watch for P20
 * let this program run in parallel with PLC 1


 * What happens with P10?

3.2 Counting seconds
code format="matlab" M10->X:$0700,0,24,S close open plc 3 clear
 * Make a third PLC program for PLC 3 that counts the seconds based on a hardware timer.
 * contents:

P39=1000*8388607/I10 M10=P39 while (M10 > 0) P31=(P30*1000)+(M10/(8388607/I10)) endw P30=P30+1

close enable plc 3 code > M10 points to the hardware timer, it is initialized with precisely the amounts of ticks for //one// second. > M10 counts down automatically. > The PLC program waits until the counter is down to 0, meaning that a second has passed. At that moment, variable P30 is incremented. So P30 counts the seconds since startup. > P31 counts the milliseconds since startup
 * this program does the following:
 * add a watch for P30 and for P31
 * let this program run in parallel with PLC 1 and PLC 2

Variable P30 counts the seconds, independent of activities of other running programs. With this seconds counter, we can examine how much iterations a PLC program can do per second.

code format="matlab" P10=P10+1 IF (P12<P30) P12=P30 P11=P10 P10=0 ENDIF code
 * modify the body of PLC 1 into:


 * explain the meaning of P11 and P12
 * modify the body of PLC 2 in a similar way (use new variables P21 and P22)
 * run only PLC 1 and PLC 3 in parallel
 * run PLC 1, PLC 2 and PLC 3 in parallel
 * explain what happens with P11 and P21

3.3 PLC 0
PLC 1 until PLC 31 run in the //background// as often as possible, i.e. all remaining time which is not used by the servo programs and the foreground programs. PLC 0 is a //foreground// program (which runs once at each Real-Time Interrupt)

code format="matlab" P0=P0+1 IF (P2<P30) P2=P30 P1=P0 P0=0 ENDIF code
 * Make a program for PLC 0 with body:


 * add a watch for P1 and P2
 * let this program run in parallel with PLC 3 (so stop PLC 1 and PLC 2)
 * then start PLC 1
 * then start PLC 2
 * what happens with the variables P1, P11, P21?


 * Examine the meaning of variable I8 (Read "PMAC AND PMAC 2 Software.pdf", page 26)
 * In the //terminal// window, examine the current value of I8 and change the value of I8 (See "PMAC AND PMAC 2 Software.pdf", page 232)
 * Explain what happens with PLC 0, PLC 1 and PLC 2
 * again: what happens with the variables P1, P11, P21.


 * Restore I8 to its original value
 * Examine the meaning of variable I10 (Read "PMAC AND PMAC 2 Software.pdf", page 28)
 * In the //terminal// window, examine the current value of I10 and change the value of I10 (See "PMAC AND PMAC 2 Software.pdf", page 232)
 * Explain what happens with PLC 0, PLC 1 and PLC 2
 * again: what happens with the variables P1, P11, P21.

3.4 CPU overload
The CPU time has to be divided over the servo control, the foreground tasks (motion control and PLC 0) and the background tasks (PLC 1..31).

If you put more statements in the programs, then at a given moment, the PMAC cannot handle it anymore. The PMAC has internally a //watchdog//, which checks that all jobs have been finished before the next servo interrupt comes. Remember the most important job of the PMAC: controlling the motors must be very accurately!!! So when the watchdog sees that it is too busy, it stops all programs immediately (to avoid that incorrect operating motors ruin the complete system).


 * Simulate this overload by adding statements in the running PLC programs, or by creating and running more PLC programs.
 * Watch the variables P1, P11, P21 etc.
 * What happens in the PC program when the PMAC stops?
 * Fortunately, the PMAC is not broken, you can simply reset it by giving the ^D command in the //terminal// window.

=4 Week 2=

4.1 Motor movements
code format="matlab" close open prog 1 clear
 * put the system in open-loop: enter command "k" in the //terminal// window
 * now you can turn the motor with your fingers
 * put the system in closed-loop: enter command "$" in the //terminal// window
 * enter command "hmz" to reset the position counter
 * now you can manually turn the motor with difficulty: the motor wants to stay at its original position
 * create a new file (File -> New File -> prog1.pmc) and write the following motion program:

linear abs

ta 2000 f 25

n 1 x 180 dwell 100 x 0 dwell 100

goto 1

close code


 * Notes:
 * X 180 means: goto position 180
 * n 1 is just a label for the goto at the bottom
 * dwell 10 let the motion program wait for 10 milliseconds
 * download it
 * let it run: command "b1r"
 * Investigate the functionality of the statements F, TA (See "PMAC AND PMAC 2 Software.pdf", between pages 292 and 359)
 * Examine what the motor does, watch the position indicator
 * Note:
 * One revolution of the motor gives 2000 counts, those counts are visible in the position window. However, in the motion program, you write statements dealing with //revolutions//, not with counts. So beware that there is a difference.
 * Make a plot of the motor behavior: collect data for about 5 to 10 seconds (see also paragraph 2.4 ("plotting on the screen")
 * stop the program: command "a"
 * Modify the motion program: you can freely change the numbers behind statements F, TA and/or X (may be larger or smaller)
 * Download the program, put the PMAC in closed loop and let it run.
 * Explain what happens, make a new plot.
 * There is a fourth statement, TM (Look up its functionality in "PMAC AND PMAC 2 Software.pdf", between pages 292 and 359).
 * Stop the motion program, delete the F statement, insert statement TM 5000, and run the program again (make a plot)
 * Explain the relation between the statements X, F, TA, TM (draw a picture)

> What is the difference with the previous plot (with the DWELL statements)? What does this mean?
 * Delete the two lines DWELL 10 and run it again
 * Make a plot where you have to make sure that there is a moment that the motor is changing direction (from left to right turning, or from right to left turning)

4.2 PID control
Inside the PMAC, a PID-loop controls the motor. In subsequent courses, the theory of PID will be covered in depth. See also:
 * []
 * []
 * []

In this workshop, you will be able to get a feeling of the PID.

The P component is stored in variable I130. The I component is stored in variable I131 The D component is stored in variable I132

Get the default values of these variables and write them down, such that you can restore them afterwards.

To get a feeling of the P component, set the variable to the following values: code format="matlab" i130=200 i131=0 i132=0 code

> however, with the current PID-values, it has an overshoot, so it passes the original position with a certain speed, and the motor will be reversed etc.
 * with your fingers, turn the wheel a quarter revolution. the feel the motor who wants to turn the wheel back.
 * if you turn another quarter revolution, the force of the motor becomes stronger.
 * when you release your fingers, the wheel will be restored to its start position.

To get a feeling of the I component, set the variable to the following values: code format="matlab" i130=50 i131=100000 i132=4000 code


 * with your fingers, turn the wheel one revolution and hold it for several seconds
 * after a while, you feel that the motor force increases

Please contact the lab assistent if you want to do more experiments with the PID values.

=5 Week 3=

5.1 buttons & leds
Attach the cable of the print with leds and buttons to the PMAC2.

The connection of the leds and buttons to the PMAC2 is memory-mapped. This means: by writing values to a dedicated memory address, the leds are turned on or turned off. And by reading a dedicated memory address, you can see which button is being pressed. code format="matlab" M40->Y:$C082,8,8,U M41->Y:$C082,0,8,U close open plc 4 clear
 * Make a program for PLC 4 with body:

P41=M41 if (P41 = $FF) P40=P40+1 endif M40=P40

close enable plc 4 code

> M40 points to the 8 leds, writing to this variable changes the status of the leds (i.e. either turned on or off). Each bit in this variable represents one led. > M41 points to the buttons memory; reading this variable gives the actual status of the buttons. Each bit in this variable represents one button. > if you press a button, is the corresponding bit //zero// or //one//? M40=M41
 * explanation of the program:
 * run this program;
 * which led is connected to the most significant bit, and which led is connected to the least significant bit?
 * is a led //on// when the corresponding bit is //zero// or //one//?
 * add a watch for P41; unfortunately, the value is given in //decimal// notation (so you have to convert the values into binary or hexadecimal notation)
 * what happens if you start other PLC programs? (e.g. PLC 0, PLC 1, PLC 2 and PLC 3 of the previous week)
 * explain what the statement "P41=M41" does
 * explain what the statement "M40=P40" does
 * what happens if you press a button? what happens if you press a button for a short or a long period of time?
 * what happens if you change the body of the PLC 4 program into the following:

5.2 bits
code format="matlab" M40 = $FF - P40 P41 = $FF - M41 code
 * change the body of PLC 4 into

with these statements, you can make a logical inverter (zero becomes one, and a one becomes a zero) without using additional hardware. code format="matlab" P40=$E3 %(repeat this and change value $E3 into something else in the range $00 - $FF) P40=P40 | $04 %explanation: whatever the value of P40 was, now the third led is turned on P40=P40 & $FB %explanation: whatever the value of P40 was, now the third led is turned off P40=P40 * 2 %explanation: all bits are shifted one position to the left P40=P40 / 2 %explanation: all bits are shifted one position to the right code
 * for simplicity, you can give the following commands in the terminal (instead of changing the PLC program):

validate these exercises carefully by computing the binary values code format="matlab" P42=P41 & $01 P43=P41 & $02 P44=P41 & $04 P45=P41 & $08 P46=P41 & $10 code
 * add the following lines to the PLC 4 program:

and add watches for these variables explain what happens if you press the buttons

enter more statements to the PLC program to handle the last two buttons as well. > this can be implemented if: write this program; use (e.g.) P49 for storing the previous status.
 * we want to have a program that increments P40 only one time when one particular button is pressed (and not //during// the press).
 * you know the status of the buttons in the previous execution
 * you take action only when the new status differs from the previous status

=6 Week 4= In this week you can make a project on your own.

Idea's: > make sure to synchronize between the PLC program which reads the buttons and the motion program which has to react on the buttons.
 * use buttons to start the motor, to stop the motor and to increase/decrease the speed
 * in the memory address of the buttons, there is 1 bit coming from a light diode (measuring //black// one time per revolution)
 * use the light diode to measure the speed of the motor, and use the lights to indicate this speed.
 * maybe you can make an elevator (with buttons for each floor etc)