-
Notifications
You must be signed in to change notification settings - Fork 2
The motor definition file
The motor definition file describes all the motors that are to be controlled. It is a json document with a section for each motor.
Each section provides a name for the motor and then defines the gpio pins used to control the motor as well as various other setings to control it's behaviour.
The setup of the gpio pins for the different motor controller classes is detailed in Motor Definition Quickstart. This section explains the stepmodes section for each motor.
Step timings are provided for each motor (and apply to all motor classes).
The step timings are also provided by classes, although only the name is needed to specify the type of step timing. Different types of timing have different parameters.
A number of modes can be defined for each stepper. Each mode defines in detail various how steps are timed and if each step is controlled by software or DMA. Step frequencies higher than the stepper's maximum start frequency should always use DMA control to prevent stalling.
Each step mode names a class used to generate a particular sytle of step timings, and has a set of parameters that define the class' operation.
It also defines if the stepper is to be driven directly by software, or by pre-calculated memory blocks that use DMA to drive the GPIO pins.
Direct software control uses code that drives each step in code in real time. This allows for immediate and direct feedback of the timings, but also means that the timing of individual steps can vary because of process scheduling and other characteristics of the software environment and operating system. Ths limits the speed the motor can use to below the maximu start frequency. Timing is typically accurate to around 1/1000 second, but can occasionally be worse. Single core processors (such as raspberry pi zero) will have far more variability than multi-core processors.
Memory DMA control prepares step timings in advance (for however many motors are running in this mode), and thus provdes highly accurate timings in a very consistent manner for speed ramping and constant speed operation. Timing should be accurate to 1 microsecond (see pigpio documetation for further details). However because the timings are prepared in advance, timings cannot be immediately modified (for feedback control for example). This technique typically prepares memory blocks 1/10 to 1/2 of a second in advance, so any changes will have around this delay before they take effect.
Every stepmode has a name and 2 standard parameters. These are followed by further parameters that depend upon the style of stepping.
"stepmodes": {
"softone": {
"stepclass" : "onespeed",
"mode" : "software",
# further parameters specific to the stepclass
},
"softramp": {
"stepclass" : "constramp",
"mode" : "software",
},
"dmaone": {
"stepclass" : "onespeed",
"mode" :"wave",
},
"softone", "softramp" and "dmaone" are the names used for the step modes. Any name can be used, and these names are used to control how the stepper will run when a run or goto command is issued.
The 2 fixed parameters of a stepmode are:
stepclass
The name for the class used to provide step timings. The step timings can be used by the software or DMA control methods.
mode
This can be "software" or "wave".
Software driven means the step class is requested to provide the time delay to the next step immediately after a step pulse has been issued. The software runs in a separate thread so is partially isolated from the effects of other running software. There will be jitter (typically a few milli-seconds at worst, but occasional longer delays are possible - especially on single core CPUs (such as a pi Zero).
Wave means memory blocks of step timings are produced in advance and DMA is used to drive the GPIO pins. Timing accuracy is very high (to around 1 micro-second) and there should be no measurable jitter greater than 1 microsecond.
Since the timing generation is separate from the software / wave code, either mode can be used with any timing generator.
Further stepmode parameters are specific the the timing generator. Two are defined in the module intervalgen.py
Note that step times are specified for a full step. The code automatically adjusts for the microstep level in use.
The step timing generators also monitor various parameters and will (for example) reverse direction on the fly.
This has a single value: The step time, specified in seconds as a floating point number. 0.01 is 100 steps per second.
The generator monitors the stepmode's step variable and will adjust on the fly for any change.
In goto mode, the generator monitors the motor's targetrawpos variable and adjusts on the fly for any change.
In run mode, the generaor monitors the motor's target_dir variable and adjusts on the fly for any change.
This has 3 parameters:
startstep: The step interval to use when starting
minstep: The minimum step interval to use (The fastest it will go)
slope: The rate of acceleration (or deceleration)
In goto mode the motor will accelerate to the minimum step time, adjusting the timing of each step appropriately. Once minimum step time is reached it runs at constant speed, and then decelerates to a stop at the target position. The motor will also decelerate to stop and then accelerate in the reverse direction if necessary.
In run mode the motor will decelerate when asked to stop or change direction.