Open Source Motion Control Part 1 Basics Based
Open Source Motion Control Part 1 Basics Based on the Etherlab open source Ether. CAT master (www. etherlab. org) Anders Sandström ESS Motion Control and Automation Group www. europeanspallationsource. se
Outline • • Motion Control: • Overview • Control Loops • Feed Forward Ether. CAT: • Fieldbus overview • Control Loops in motion systems • Feed Forward and Trajectories ECMC (Ether. CAT Motion Control): • Architecture • Hardware Configuration Tree • Axis, Trajectory, Monitor, Controller, Drive, Encoder • Data links • Documentation • Configurations Acknowledgments 2
Motion: Overview Electronics Mechanics
Motion: Control Loops Current Control Loop: Needed for both open and closed loop setups (however depends on actuator) Functionality depends on motor type (phase shift output for commutation) Current is related to torque via the motor KT constant for rotary motors or to a force for linear motors. Common sample rate range: 10 -50 k. Hz Type: PI controller (maybe filters, observer) Velocity Control Loop: Needed for closed loop, sometimes used for open loop (frequency control) Common sample rate range: 1 -10 k. Hz Type: PI controller Position Control Loop: Needed for closed loop, sometimes used for open loop (for consistency) Common sample rate range 100 -5 k. Hz Type: P or PI controller (if P the stationary error will be handled by velocity PI) 4
Motion: Control Loops cont. Speed Control SPSpeed =FFSpeed OPosition SPPosition + + P(ID)Positio - n + + PI(D)Speed Current Control FFI + + PI(D)I PVSpeed Process Position Control PVPosition SPPosition setpoint SPSpeed Setpoint OPosition offset FFspeed Speed forward PVPosition Actual position PVSpeed Actual speed Mech. , motor, feedback 5
Motion: Feed Forward and Trajectory Already known changes can be fed forward. The error for the controller to handle will be less. Scaling of velocity feed forward is made by setting the drive scale parameters. P(ID)Position + PI(D)Speed + PI(D)I (torque) 6 Process
Motion: Feed Forward Target position Actual position Trajectory generator set-point Position Controller output Already known changes can be fed forward to increase performance. The error for the controller to handle will be smaller. Feed Forward output (to speed PID) Feed Forward Position / Output No Feed Forward Time Feed Forward handles main part of the control Position controller only handles small deviations Time 7
Ether. CAT: Overview • Ether. CAT = Ethernet for Control Automation Technology • Open fieldbus standard originally developed by Beckhoff Gmb. H • Maintained by Ether. CAT Technology Group (www. Ether. CAT. org). • Hardware requirements: –Master: standard computer hardware (NIC) –Slaves: dedicated hardware, Ether. CAT Slave Controller (ESC) • Masters: Several commercial and open source masters available • Slaves: Several 100 manufacturers of slaves (drives, I/O, sensors, robots) • Topologies: Line, Star, Ring • Media: Cat 5 cable, plastic fiber, glass fiber • Supports Distributed Clock (DC) in slaves • Bandwidth utilization: 80%-97% (100 Mbit/s , Ethernet, Full-Duplex) • Applications: Motion, large or long distance systems, synchronized systems • Cycle times > 50μs
Ether. CAT: Control Loop Execution Options CSP-Mode CSV-Mode CST-Mode Cyclic Sync. Position Cyclic Sync. Velocity Cyclic Sync. Torque - Trajectory gen. - No control Act. position Amplifier Level Position setp. Control: • Pos. • Velo. • Torque Controller: No loops needed Drive: All control loops -Trajectory gen. -Position cont. -Velocity cont. -Trajectory gen. -Position cont. Act. position Velocity setp. Act. position Control: • Velo. • Torque Controller: Position loop Drive: Velocity and current loop Torque setp. Control: • Torque Controller: Position, velocity loop Drive: Current loop 9
ECMC: Ether. CAT Motion Control ECMC is an open source motion control framework for EPICS environment [10]. Functionalities: • Motion (with EPICS Motor Record support): - Positioning (absolute, relative) - Constant speed - Referencing sequences • Motion (extension to Motor Record) - Motion interlocks - Triggering, latching positions - Synchronization axis to axis - Synchronisation to external source (timing system) • General - Data acquisition (analogue <100 k. Hz, digital <1 Mhz) - General I/O + low level control - SDO , Oversampling terminals 10
ECMC: Overview HMI (CSS, BOY) Channel Access Linux Controller (Centos) EPICS IOC Model 3 driver, Asyn Motion Control (ECMC) Ether. CAT Drive XXXX Digital Analog Ether. CAT Terminals Drive XXXX Digital Ether. CAT Terminals Analog Ether. CAT Drive Igh open source Ether. CAT master (www. etherlab. org) 11
ECMC: Architecture Controller (Linux) Epics IOC (soft. Ioc) Asyn model 3 driver Asyn Motion Controller (ECMC) Communication Thread Direct access (I/O Intr) Command parser Motion Thread (1 k. Hz) Axis 1 Axis 2 Axis 3 Axis 4 Axis N Ether. CAT process image ecrt. h Ether. CAT master Ether. CAT Master n 12
ECMC: Axis object “Cfg. Create. Axis(…)” Encoder EC master PID-Control Trajectory ECPdo. Entry Transform / Expression Transform /Expression Encoder Y Trajectory Z Optional link: Sync. External • Optional link: Sync. Trajectory Types: Normal, Virtual Monitor Drive ECPdo. Entry EC master Executes and links objects: • • • Axis Encoder Trajectory Generation PID-Controller Monitor Drive Sequences • Homing (different types) 14
ECMC: Configuration All configuration in EPICS startup file: ECMC configurations (speed, acceleration…. . ) Terminal configurations (Service Data Object access: max current, mode…)
ECMC: Configuration cont. The motion system is precompiled as an EEE-module (ESS Epics Environment module) and only needs configuration (“require ecmc”). Configuration command: Ethercat. MCConfig. Controller ”asynport” “command” Return values for commands: 0 for success or otherwise error code. Example 1: Create Axis 1 object: Ethercat. MCConfig. Controller “MCU 1” ”Cfg. Create. Default. Axis(1)” Example 2: Set position controller gain for axis 1 to 0. 1 Ethercat. MCConfig. Controller ”MCU 1” ”Cfg. Set. Axis. Cntrl. Kp(1, 0. 1)” 22
ECMC: Startup file structure part 1 1. Require 2. Asyn config 3. Misc settings 23
ECMC: Startup file structure part 2 Hardware configuration 1. Choose master 2. Configure I/O slaves: 1. Set slave bus position 2. “include” “snippet” 3. Configure motion hardware: 1. Set slave bus position 2. Drive “snippet” 3. Motor “snippet” 24
ECMC: Startup file structure part 3 1. Configuration of axes 1. Axis configuration snippet (custom settings for axis) 2. Apply settings with the snippet ”ecmc. MCU-10 xx. Axis” 2. Diagnostics 3. Load controller records 4. Start real time thread 25
ECMC: Hardware Configuration EC Master “Cfg. Ec. Add. Slave(…)” EC Slave 0 EC Slave N EC SM 0 EC PDO 0 EC SM 1 EC PDO 0 EC SM X EC PDO 1 EC PDO Y EC PDO Z Cfg. Ec. Add. Entry. Complete() ECPdo. Entry ECPdo. Entry EC Pdo. Entry EC Slave …
ECMC: Hardware Configuration Choose Ether. CAT master with index n: “Cfg. Ec. Set. Master(n)” // Choose Ether. CAT master Configure a PDO entry (data entry): “Cfg. Ec. Add. Entry. Complete(slave. Position, // Slave position on Ether. CAT bus vendor. Id, // Id of vendor (see documentation) product. Code, // Id of product direction, // data direction 1=output, 2=input sync. Manager. Index, // index of sync manager pdo. Index, // index of process data object (pdo) entry. Index, // index of entry inside pdo entry. Sub. Index, // sub index of entry bits, // bit size alias)” // String for later linking Example: Beckhoff EL 1018 slave. Pos=0, vendor. Id=0 x 2, product. Code=0 x 03 fa 3052, direction=2, sync. Manager. Index=0, pdo. Index=0 x 1 a 00, entry. Index=0 x 6000, entry. Sub. Index=0 x 1, bits=1, Alias=INPUT_0 “Cfg. Ec. Add. Entry. Complete(0, 0 x 2, 0 x 03 fa 3052, 2, 0, 0 x 1 a 00, 0 x 6000, 0 x 1, 1, INPUT_1)” Apply hardware configuration for master 0 Cfg. Ec. Apply. Config(0) accessible) // Apply hardware config (Ether. CAT bus must be Note: All Ether. CAT entries , including arrays/waveforms, can be pushed to EPICS records as “I/O Intr” over asyn (max update rate is the same as the motion thread, default 1 k. Hz). 28
ECMC: Hardware Configuration Safety: ECMC is a control framework (not only data acq. ). Controlling wrong hardware could result in serious situations damaging equipment or even hurting people. Therefore, ECMC will only go to run-time if hardware configuration matches what is found on the Ether. CAT bus (same as Twin. CAT): • Ether. CAT product ID and vendor ID needs to be correct • PDO addresses needs to be correct (absolute addressing) Hardware Support: Many complex slaves needs manual configuration: • Many servo drives (Example Technosoft IPOSXXXX, Kuhnke FIODrive. . ) • Oversampling terminals (Example EL 3632, EL 3702) Note: ECMC has a few auto configuration features implemented but should NOT be used for motion applications. 29
ECMC: Supported Hardware • • • • • EK 1100 -Ether. Cat. Coupler EK 1101 -Ether. Cat. Coupler. ID EK 1110 -Ether. Cat. Extension EK 1122 -Ether. Cat. Junction EL 1018 -digital. Input EL 1252 -digital. Input EL 2808 -digital. Output EL 2819 -digital. Output EL 3002 -analog. Input EL 3162 -analog. Input EL 3204 -analog. Input EL 3214 -analog. Input (PT 100(0), TC) EL 3255 -potentiometer. Input EL 3602 -analog. Input EL 3632 -analog. Input-50 (oversampling) EL 3702 -analog. Input-10 (oversampling) • • • • • EL 4032 -analog. Output EL 4134 -analog. Output EL 5002 -ssi. Encoder EL 5021 -Sin. Cos. Encoder EL 5101 -Inc. Encoder EL 6080 -memory EL 7031 -Stepper. Drive EL 7037 -Stepper. Drive-Pos. IF EL 7041 -Stepper. Drive EL 7047 -Stepper. Drive EL 7201 -Servo. Drive EL 9410 -power. Supply. EBus EL 9505 -power. Supply 5 V EL 9576 -Brake. Chopper FIODrive-Stepper. Drive IPOS 4808 -drive. CSV IPOS 8020 -drive. CSV Note: New hardware support is continuously added!
ECMC: Axis Configuration Create an axis object at index n: “Cfg. Create. Default. Axis(n)” // Create axis object of type 1 (Normal axis) Configure dynamics for axis object at index n: "Main. Mn. f. Acceleration=acc” "Main. Mn. f. Deceleration=dec” "Cfg. Set. Axis. Emerg. Deceleration(n, emergdec)” "Main. Mn. f. Velocity=vel” "Cfg. Set. Axis. Home. Vel. Twords. Cam(n, vel)” "Cfg. Set. Axis. Home. Vel. Off. Cam(n, vel)” // Set acceleration // Set deceleration // Set emergency deceleration // Set target velocity // Homing velocity twords cam // Homing velocity off cam Define motion command (see documentation for FB_Drive. Virtual): "Main. Mn. n. Command=cmd” cmd=0: Jog cmd=1: Constant Velocity cmd=2: Relative Positioning cmd=3: Absolute Positioning cmd=10: Homing/referencing 31
ECMC: Axis configuration snippet 1. Custom config. for each axis: 1. General 2. Encoder 3. Drive 4. Trajectory 5. Homing 6. Controller 7. Monitoring 32
ECMC: PID Controller Configuration Configure control parameters (position loop) for axis n: "Cfg. Set. Axis. Cntrl. Kp(n, kp)” // Gain "Cfg. Set. Axis. Cntrl. Ki(n, ki)” // Integration gain "Cfg. Set. Axis. Cntrl. Kd(n, kd)” // Differentiator gain "Cfg. Set. Axis. Cntrl. Kff(n, kff)” // Velocity feed forward gain "Cfg. Set. Axis. Cntrl. Out. HL(n, outhl)” // Maximum controller output "Cfg. Set. Axis. Cntrl. Out. LL(n, outll)” // Minimum controller output Example: Set controller gain to 5. 0 for axis 2 (on asynport MCU 1): Ethercat. MCConfig. Controller ”MCU 1” “Cfg. Set. Axis. Cntrl. Kp(1, 5. 0)” 33
ECMC: Encoder Configuration Configure encoder parameters for axis n: "Cfg. Set. Axis. Enc. Scale. Denom(n, scale. Denom)” "Cfg. Set. Axis. Enc. Scale. Num(n, scale. Num)” "Cfg. Set. Axis. Enc. Type(n, type)” "Cfg. Set. Axis. Enc. Bits(n, bit. Count)” // Set encoder scale denominator // Set encoder scale numerator // type=0: incremental encoder // type=1: absolute encoder // set bit count "Cfg. Link. Ec. Entry. To. Axis. Encoder(slave. Position, alias, n, encoder. Entry. Index, bit)” // Slave position on Ether. CAT bus // alias defined Cfg. Ec. Add. Entry. Complete(. . ) // axis index // encoder. Entry. Index=0: Actual position // bit to use (-1= all bits) Example: Link Ether. CAT entry with alias “POSITION” on slave 2 as encoder actiual value on axis 5: Ethercat. MCConfig. Controller ”MCU 1” “Cfg. Link. Ec. Entry. To. Axis. Encoder(2, POSITION, 5, 0, -1)” 34
ECMC: Drive Configuration Configure drive parameters for axis n: "Cfg. Set. Axis. Drv. Scale. Denom(n, 32768. 0)” "Cfg. Set. Axis. Drv. Scale. Num(n, 600. 0)” // Velocity scale denominator // Velocity scale numerator "Cfg. Link. Ec. Entry. To. Axis. Drive (slave. Position, alias, n, drive. Entry. Index, bit)” // Slave position on Ether. CAT bus // alias defined Cfg. Ec. Add. Entry. Complete(. . ) // axis index // See below // bit to use (-1= all bits) drive. Entry. Index=0: Enable Cmd/Control Word (output) drive. Entry. Index=1: Velocity setpoint (output) drive. Entry. Index=2: Enabled/Status Word Example: Link Ether. CAT entries to drive object of axis 2 for a simple stepper drive on slave position 6: Ethercat. MCConfig. Controller ”MCU 1” “Cfg. Link. Ec. Entry. To. Axis. Drive(6, STM_CONTROL, 2, 0, 0)” Ethercat. MCConfig. Controller ”MCU 1” "Cfg. Link. Ec. Entry. To. Axis. Drive(6, VELOCITY_SETPOINT, 2, 1, -1)” Ethercat. MCConfig. Controller ”MCU 1” "Cfg. Link. Ec. Entry. To. Axis. Drive(6, STM_STATUS, 2, 2, 1)” 35
ECMC: Monitor Configuration Configure monitor parameters for axis n: "Cfg. Set. Axis. Mon. At. Target. Tol(n, 0. 1)” // “At target” tolerance band "Cfg. Set. Axis. Mon. At. Target. Time(n, 100)” // “At target” time “filter” "Cfg. Set. Axis. Mon. Enable. At. Target. Mon(n, 1)” // Enable/Disable at target mon. "Cfg. Set. Axis. Mon. Pos. Lag. Tol(n, 0. 5)” // Position lag tolerance band "Cfg. Set. Axis. Mon. Pos. Lag. Time(n, 10)” // Position lag time “filter” "Cfg. Set. Axis. Mon. Enable. Lag. Mon(n, 0)” // Enable/Disable Position lag mon. "Cfg. Set. Axis. Mon. Max. Vel(n, 100)” // Set maximum velocity "Cfg. Set. Axis. Mon. Enable. Max. Vel(n, 1)” // Enable/Disable velocity mon. "Cfg. Set. Axis. Mon. Max. Vel. Drive. ILDelay(n, 500)” // Vel. mon. drive time delay "Cfg. Set. Axis. Mon. Max. Vel. Traj. ILDelay(n, 200)” // Vel. mon. traj time delay 36
ECMC: Monitor Configuration cont. : "Cfg. Link. Ec. Entry. To. Axis. Monitor (slave. Position, alias, n, monitor. Entry. Index, bit)” // Slave position on Ether. CAT bus // alias defined Cfg. Ec. Add. Entry. Complete(. . ) // axis index // See below // bit to use (-1= all bits) monitor. Entry. Index=0: Limit switch backward direction monitor. Entry. Index=1: Limit switch forward direction monitor. Entry. Index=2: Home/Reference Switch monitor. Entry. Index=3: External Interlock (optional) Example: Link Ether. CAT entries to drive object of axis 2 for a simple stepper drive on slave position 6: Ethercat. MCConfig. Controller "MCU 1", "Cfg. Link. Ec. Entry. To. Axis. Monitor(0, INPUT_1, 1, 0, 0)" Ethercat. MCConfig. Controller "MCU 1", "Cfg. Link. Ec. Entry. To. Axis. Monitor(0, INPUT_3, 1, 1, 0)" Ethercat. MCConfig. Controller "MCU 1", "Cfg. Link. Ec. Entry. To. Axis. Monitor(0, INPUT_2, 1, 2, 0)” Example: Override limit switches with simulation entries (use slave position -1 and alias “ONE”): Ethercat. MCConfig. Controller "MCU 1", "Cfg. Link. Ec. Entry. To. Axis. Monitor(-1, ONE, 1, 0, 0)" Ethercat. MCConfig. Controller "MCU 1", "Cfg. Link. Ec. Entry. To. Axis. Monitor(-1, ONE, 1, 1, 0)" 37
ECMC: Diagnostics / Error handling Diagnostics: “Cfg. Ec. Set. Diagnostics (enable)” // Enable/disable EC diagnostics IMPORTANT “Cfg. Ec. Enable. Printouts (enable)“ “Cfg. Set. Diag. Axis. Index (axis. Index)” “Cfg. Set. Diag. Axis. Freq (freq)” “Cfg. Set. Diag. Axis. Enable (enable)” // Enable/disable printouts from axis objects “Cfg. Set. Enable. Time. Diag (enable)” “Cfg. Set. Enable. Function. Call. Diag (enable)“ "Cfg. Set. Trace. Mask. Bit(15, enable)” // Enable/disable on change axis diagnostics Error commands: “Cfg. Ec. Reset. Error ()” get. Controller. Error () controller. Error. Reset () get. Error. String (error. Number) Axis specific error commands for axis n: “Main. Mn. n. Error. Id? ” “Main. Mn. s. Error. Message? ” “Main. Mn. b. Error? ” // get. Axis. Error. ID (n) // get. Axis. Error (n) 38
Terminal Configurations (SDO) Access to terminal specific settings is over SDO access: - Ec. Add. Sdo() write and verify SDO - Ec. Write. Sdo() write SDO - Ec. Read. Sdo() read SDO “Cfg. Ec. Add. Sdo(slave. Bus. Position, sdo. Index, sdo. Sub. Index, value, byte. Size )” // Slave position on Ether. CAT bus // Sdo index address (see manual for terminal) // Sdo sub index address (see manual for terminal) // value to write // number of bytes to write Example 1: Set maximum current to 1000 m. A on EL 7037 (slave 6): Ethercat. MCConfig. Controller ”MCU 1” "Cfg. Ec. Add. Sdo(6, 0 x 8010, 0 x 1, 1000, 2)” 39
ECMC: Documentation ECMC: • Doxygen documentation for all commands can be found in hw_motor. h (and ecmctraining/doc/html/index. html) • Wiki: https: //ess-ics. atlassian. net/wiki/display/MCAG/Open+Source+Motion+Control Etherlab (Ether. CAT master): • www. etherlab. org Hardware: • www. beckhoff. com • … 42
Etherlab Ether. CAT tool: Ether. CAT tool from www. etherlab. org Display master status: ethercat master Display slaves and status: ethercat slaves Display available PDOs for slave 3: ethercat –p 3 pdos Display available SDOs for slave 3: ethercat –p 3 sdos Display help: ethercat –h 43
Acknowledgments • Igh open source Ether. CAT master (www. etherlab. org) • EPICS community (base, motor, asyn, stream device) • Expr. TK C++ Mathematical Expression Library (www. partow. net/programming/exprtk) Questions? 44
- Slides: 34