Smart Stepper command line interface
The smart stepper uses a command line interface where the prompt is “:>”
|The help command will return a list of commands that the smart stepper supports.|
|This command will print out the 200 point calibration table. This is useful if you are doing firmware development and do not want to calibrate each time you update firmware. You can take this table and copy it into the nonvolatile.cpp file as shown below|
|This will run a 200 point calibration of the encoder. Should be done with motor disconnected from machine|
|This will test the calibration and report the maximum error in degrees.|
|This command gets/sets the number of microsteps the smart stepper will use for the step command and the step pin. The number of microsteps does not affect the resolution of the controller but rather how fine you can set the position.|
|This will move the motor one step clockwise, the step size is based on the current microstep setting. To move the motor counterclockwise use “step 1”. To move the motor clockwise 16 steps used “step 0 16” to move motor counterclockwise 16 steps use “step 1 16”|
This commands disable/enables feedback control loop. 'feedback 0' - disables, 'feedback 1' - enables
The plan is to discountinue this command in the future and use the “controlmode” command to put controller in open or one of the many closed loop operational modes.
|Reads the current motor position and reports it as degrees (current angle as 16bit number) applies calibration if valid|
|This command will read and report the AS5047D internal registers for diagnostic purposes.|
|This command sets the Kp, Ki, and Kd terms for the simple positional PID controller.|
|This command sets the Kp, Ki, and Kd terms for the positional PID controller.|
|This command sets the Kp, Ki, and Kd terms for the velocity PID controller.|
|This sets the velocity in RPMs to rotate motor when unit is configured for velocity PID mode of operation.|
|This command will put the microprocessor in the boot loader mode. Alternatively this can be done by double pressing the reset button.|
|This erases the calibration and other system and motor parameters such that unit is reset to the factory ship state. After this command the unit will need to be calibrated to the motor again.|
|This command sets which direction the motor will rotate when direction pin is pulled high. The direction pin is only sampled when the step pin has a rising edge. ‘dirpin 0’ will set the motor to rotate clockwise when dir pin is high ‘dirpin 1’ will set the motor to rotate counter-clockwise when dir pin is high|
Gets set the maximum number of degrees of error that is acceptable, any posistioning error about the error limit will assert the error pin, when error pin is set as error output. For example:
Will set the error limit to 1.8 degrees.
Gets/Sets the feedback controller mode of operation. The command takes an integer from 0 through 4 to set the control mode per table below:
If you are unsure what you are doing leave unit in the Simple PID mode of operation.
|This sets the maximum current that will be pushed into the motor. To set the current for maximum of 2.0A you would use command “maxcurrent 2000” as the argument is in milliAmps.|
|For the Simple Positional PID mode the minimal current (ie current with no positional error) is the hold current. You set this current based on the required holding torque you need for your application. The higher the hold current, the hotter and noisier the motor will be but also the larger the holding torque. For the Positional PID mode the PID tuning params have to be set correctly such that the control loop will dynamically determine the holding torque. This tuning of the PID can be difficult, hence the simple PID mode will work most of the time out of the box by setting maximum current and holding current.|
|The firmware always uses a positive angle as a clockwise rotation. A stepper motor however could have wiring done with one coil reversed wired, which will cause motor to normally operate in opposite direction. The Smart Stepper firmware will detect the motor wiring direction, using the encoder, and the firmware will compensate for a reverse wired motor. The reverse or forward wiring of a motor is detected on first power up after factory reset. If the wiring changes after that you can compensate using this command. HOWEVER it is better to do a factory reset and recalibrate motor if wiring changes.|
|The Smart Stepper firmware will with first power on after factory reset detect the number of full steps per rotation for the stepper motor and store in flash memory. This command will read this parameter from flash and allow user to change this parameter if motor is changed. HOWEVER it is better to do a factory reset and recalibrate motor if motorchanges.|
|The move command will request the motor to move to an absolute angle position. Optionally the user can specify the rotational speed (RPMs) by which the move should happen. For example if the current motor position is at angle 0 and you issue ‘move 3600” the motor will turn 10 rotations clockwise to angle of 3600 degrees. If issue the ‘move 3600’ again nothing will happen as motor is already at angle 3600. If motor is at angle 0 and user issues the command ‘move 3600 20’ then motor will move to 10 rotations clockwise to angle of 3600 at a rate of 20 RPMs.|
|If user issues a move command that takes a long time and wants to stop the move before completion then user can issue the stop command command which will stop a move operation. This stops the motion planner|
This command will take the current motor position and set it to absolute (reference) angle of zero. Note that if you are in the middle move it will take the position at the time of the command and use it, thus it is recommend a move be stopped or wait for completion before issuing the setzero.
|This command will toggle output of binary data.|
|This command will display the time it takes for a single processing (control) loop to execute.|
|This command displays the motor error in degrees difference from the stored eeprom value at motor power up.|
|Displays the location of the shaft angle in degrees at motor power on.|
|Forces the eeprom to store all current values (location) in ram to eeprom.|
|Forces the eeprom to write the current shaft angle overwriting the stored location from powerup.|
|Overwrites the current shaft angle (degrees) in the motion planner.|
|Forces the smart stepper to reboot|
If using built in homing routine (command "home") this will specify the amount of current applied when motor is moving during homing operation when homepin is logic active.EXPERIMENTAL USE WITH CAUTION
gets/set the motor moving and holding currents that will be used when pin A3 is low
|Allows setting of pin for current limited enable for homing. This triggers a current drop during homing movements. Current set using command "homecurrent". This pin is pulled low to activate. EXPERIMENTAL USE WITH CAUTION|
sets the angle delay in dropping to homing current
Tells the motion controller to move motor until the home switch (enable pin) is pulled low. (Only on boards 3/21/2017 or newer) (Must be enabled in firmware). For example:
Will move up to 360 degrees at 0.5 RPM. EXPERIMENTAL USE WITH CAUTION
reads pins as binary (bit 0-step, bit 1 - Dir, bit 2 - Enable, bit 3 - Error, bit 4 - A3, bit 5- TX, bit 6 - RX
Sets or displays the error pin mode. Allows someone to swap usage of the error pin as an enable pin on older boards. (Not compiled for use on boards 3/21/2017 or newer since they have separate enable and error pins) (Must be enabled in firmware) Modes are:
Sets or displays the binary state of the enable pin. Acceptable values are 0 or 1 For example:
Will set the error pin on the terminal block to output a logic high when the error level is reached
Sets or displays the enable pin mode. Allows someone to swap usage of the enable pin as an error pin on older boards. (Only on boards 3/21/2017 or newer since they have separate enable and error pins) (Must be enabled in firmware) Modes are:
|Displays the current motor shaft error in degrees.|
|Displays the number of steps that have been seen from the DIR pin.|
|Sets if syslog debugging will be output on USB serial. Allowed values are 0 for disable, 1 for enable.|
prints torque parameter, with argument sets 'torque t' Where torque is an integer between -128 and 127. The special value
CUSTOM COMMAND FROM FORK REPO
How to access Smart Stepper by USB serial from bash
If the backspace button does not work, then the control key in PuTTY/KiTTY has to be switched to "Control-H". Otherwise "screen /dev/ttyUSB-SMART-A-AXIS" does not work correctly, because entered input cannot be deleted.
This script is not used for Trikarus project but it was worked out while trying to find working solutions with Smart Steppers.
Manual parallel working with multiple sessions
Using sreen sometimes misses some input/output with the used configuration. Some fine tuning for input and output buffers and timeouts is required!
Using PySerial and Python 3.7
This is the thing we use in production. The following script can be used as service (one service per motor) or as regular script.
To make this script working we need different timeouts for serial input/output buffering. Good working values are
- timeout=0.4 (lowest fine working value is 0.2)
- write_timeout=1.5 (lowest fine working value is 1.0)
- wait_interval = 0.4 (lowest fine working value is 0.05 )
Remove old/unrequired InfluxDB data
General information about control modes for Hangprinters
Hangprinters do not have absolute position control. Modern Hangprinters use closed loop systems to ensure exact relative positions using encoders and to have better handling in general. By using such closed loop systems it's easy to implement a special torque mode (custom firmware implementation from Torbjørn Ludvigsen) for each motor. This enables to tension all lines to a constant tension. Then you can drag the effector around with your hands and save a lot of time calibrating the machine. So the torque mode is a special calibration mode. Trikarus uses Smart Stepper from MisfitTech. It makes use of torque mode with the following mimimum and maximum values: +127 / -128 (the sign inverts the direction of movement - clockwise or counterclockwise). The special value 0 exits the torque mode to jump back to regular mode (sPID or pPID).
Smart Stepper usually run in Simple/Hybrid PID mode when shipped ("spid" → this can be enabled by serial interface command "ctrlmode 2"). However, it is also a good idea to use Positional PID mode instead of the factory setting ("ppid" → this can be enabled by serial interface command "ctrlmode 3"). To use ppid mode the PID values have to be adjusted properly.
More information about Smart Stepper modes can be found at Smart Stepper rev 1/20/2019 by MisfitTech documentation manuals.
Swichting between default mode (simple PID) and torque mode
The switching the modes is explained in Smart Stepper - flashing the firmware and polling data.
- This action can be done either by
- clicking the rotary encoder knob at the effector 5 times in a row quickly (1.0 second), or by
- triggering the button from Repetier Server GUI, or by
- calling the torque command on USB serial (e.g. using "screen /dev/ttyUSB-SMART-?-AXIS"
- To switch between torque mode and sPID mode we simply call only a single command: "torque 0" (to go back to sPID) or "torque <value != 0>" (to enter torque mode). Please explicitely do not set ctrlmode from 2 to 5 by hand using that "ctrlmode" command, because this leads to unforeseen stepper movements at the switch, which can ruin your line guidings (painfully tested). The cause might be some previously saved position values.
The behaviour in your hands → Moving the stepper motor shaft back and forth by hand, you can feel little "ticks" as you move across motor poles. Getting rid of those would make fully automatic data collection much easier.
The regular torque mode for effector dragging
Torque mode for "clean" effector dragging only works fine if it is enabled to all four drives. If you forget any of them it will do not perform. Dragging the effector by hand may require a bit of manual power because this mode is really strong. If you use doubled lines feature and a lot of bearings and ceramic inserts the friction is much higher than using single lines. Move the effector with love and touch it safely. The value you choose for torque highly depends on your installed motors and the configured currents. While having motor current at 800 mA torque of 50 is good, but changing to 1500 mA a torque value of 35 is already enough to have the same force in your hands.
Do not ever use torque mode if drives are not mounted correctly. In case the motors are not mounted to spools and/or the spool lines are not tied, the motors will turn infinite without stopping. In this scenario you will reach the maximum of encoder pos. This cannot be resetted using the "setzero" command. Instead you need to perform a full reboot of the Smart Stepper which is the same like having a power loss. It's a high risk to set torque values higher than the given counter weight. The higher the value the quicker the drive will move. It might cause unwinding all the line from your spools.
Calibration and important adjustments for Smart Steppers
Remember to run "calibrate" and "testcal" to have clean settings for each Smart Stepper. Otherwise the Stepper will run bad or it will stand still. The documentation says that a maximum angle degree error is 0.1 deg. If the motor current is set too low the motor will not move correctly (e.g. motor steps forward and backward alternating) and is going to miss steps. This will also lead to bad calibration values. If you adjust the motor current a re-calibration might be a good idea.
Adjusting the motor currents
Basically the current values are all the same because all drives have same motors attached, with nearly same amount of line on it. They drive in the same direction by wiring and roughly symmetric forces grab on it except D drive (a little higher force). Higher torque values work for different situations but have no better effect on the regular torque mode for effector dragging. But you can use higher torque values for moving up and down the effector without any GCode command. I successfully tested torque mode up to +127 without any parts falling off the machine and no cracking sounds. So everything looks really stable. This was tested with default Smart Stepper values maxcurrent = 800 mA and holdcurrent = 500 mA. The mounted stepper motors can run up to 2.0 A so there's a lot more power possible. The torque mode settings depend on your motor power. if you raise the current it will behave not the same as before. if you adjust one motor you will need to adjust all other motors too to get equivalent behaviour (having the same motor types for all four drives. Trikarus uses Stepper Motors MT-1705HS200AE by Motech Motors).
Finally after some tests with Trikarus the configuration is
- maxcurrent = 1500 mA
- holdcurrent = 800 mA
The currents are preconfigured and can easily be applied using sms_preconfigure.sh (the smartStepper Python services need to run)
As we do not make use of pPID but sPID we do not need any PID value adjustments
The default value each Smart Stepper tolerates 1.8 degrees of error until it triggers the error pin. Trikarus does not make use of that function but it could be used for brake mechanisms for example!
Bash scripts for daily use (mode switches)
The following scripts are worked out to be really useful for calibration and printing. They can be used by command line, by Repetier Server GUI command list drop down menu (see Repetier Server) or by the rotary encoder button (mode switch).
Setting zero does only reset positions to 0. It does not set the error to 0. Cleaning the error can be done by recalibrating and/or rebooting the motor!
If you cannot properly drag the effector into origin reduce the torque values. It's possible that you configured to high values. When you push down the effector it might bump up again. You might also check the motor currents.
Make them executable
Script as service
Install this script four times by just replacing the Drive letter accordingly
Mode switch recognizing with the KY040 rotary encoder button
The button of the encoder is used to always put Trikarus into torque mode after pressing the button 3 times in a row quickly (less than 1.0 second). For security reasons it does only turn into torque mode but not back to previous mode because if the printer possibly receives print commands from print queue the printer could be moving while you stand in the working area of the machine. That might cause unwanted trouble with you and the lines.