David Pilling |
Main »
Stepper PiThe Pi version of Stepper. Software for the Stepper Pi Hat. This is low level software, for a graphical user interface see Stepper Pi Node and Stepper Pi Library. On the Pi I have three motors (compared to just one on the Arduino), as a result many of the commands take an extra motor number parameter in the range 0..2. The original code was written on Arduino, to make it work on Pi, I used the: Wiring Pi - GPIO Interface library for the Raspberry Pi On Arduino the code gets commands from the serial port and responds the same way. For the Pi version I wrote an emulation of the necessary bits of the Serial class which uses standard input and output. As a result on Pi the code runs as a process and accepts typed commands, replying to the terminal. The stepper folder is intended to be contained inside the top level wiringPi folder. Use the command There was a snag with version 2.00, sudo processes are not killed when a terminal closes, as a result old invocations of stepper will continue to run. That is not too bad but there was a bug in the code which caused it to keep executing the last command line if there was no terminal present. Version 2.02 adds two command line flags; 'pipe' to create named pipes for reading and writing commands and 'debug' to copy to stdout all output. The named pipes are /tmp/stepperin and /tmp/stepperout.
For serious use, stepper is run once on boot and left running. The application for controlling the motors talks to the stepper process via the two named pipes using the Stepper Pi Library, or the node.js web app Stepper Pi Node. In the Arduino world using two letter commands to tell the stepper motor what to do seemed reasonable, but I found that giving similar two letter responses from the stepper process fitted in well with the javascript event driven model. They can also be used in text files to save configurations. In the command descriptions below those saved in the configuration file are indicated with a *. Downloads:
Commands
Set power mode 0 = off, 1= on, 2= automatic
Move, returns a message when move is complete including new position of the form:
Set speed in steps per second. *
Set acceleration in steps per second per second *
Set number of microsteps, in ti mode 32 is also allowed. *
Stop
Return current position. Gives response of the form:
Return distance to go
Read state of a pin, returns value
Write a value to a pin
Set the current position value. Allows zero point of values returned to be changed.
Make the motor run continuously at the given speed. Use a value of zero to stop.
Return software version
Enter Texas Instruments mode. Enables 32 microstep mode.
This sets the base scale, default is 16. It sets the units that step values are measured in (as a multiple of one step). Just like one can choose to measure distances in 16 ths of an inch or 8 ths of an inch (or 1000 ths of a metre). Motor movement resolution can't be less than the bs value. So if it is set to 16, the motor can move in 1/32 nds (ss =32) but will always end up on a 1/16 th position.
Test if optical sensor is present on given pin. Note the pull up resistors on the Tilt motor input mean this command is unlikely to give accurate results for that pin. Return: 0 sensor connected 1 sensor not-connected
Whilst executing commands pause for time ms.
Start executing program n. Programs are held in the array
Quit.
Arm interrupt. Mode can be 0 or 1, signifying that the corresponding level on the input pin associated with the motor means the motor should be stopped. For the current implementation there is only one input per motor and the middle parameter (the interrupt number) should be left as 0. For example ai 1 0 0 means that motor 1 will be stopped when its input pin goes low. Interrupts clear after being triggered so this command should be issued before each move that you want an input change to stop.
Remove interrupt. Disarms the given interrupt.
Return debug info on interrupt state
Shutdown Pi in given number of milliseconds. Gives response of the form:
Save settings with given name. If the name is omitted 'default' will be used. Gives response of the form:
Load settings from given name. If the name is omitted 'default' will be used. Gives a series of responses for all the saved values. Values are saved in a folder called 'profiles' in the same folder as the stepper task is run from. The profiles consist of a text file with the given name and the extension .txt. Each line in the text file contains a command from this page. For example:
The same string would be one of the responses given by the ld command.
List saved profiles. Gives a response of the form:
<n> is an index, starting from zero.
Start time lapse sequence
End sequence
Fire camera
Set up way points. Any way point of value zero is ignored.
Sequence query, find time lapse sequence information, gives a response of the form:
|
David Pilling's Wiki Set view |
Page last modified on October 21, 2016, at 12:55 AM - Powered by PmWiki pmwiki-2.3.31 (pmwiki-2.3.31) |