Page 1 of 1

Motor based multiprocessing

Posted: Mon Nov 16, 2015 2:47 pm
by Tad Hasse
Green to Python but an old fossil to computing, I looking for a call/create method for one created static child process per motor for a robotics project.

Here is list of motors and parameters Motor #, device addr, bank, type, pin assignments. For the FiveWire the relative pin order is for IN1~4 For the A4988 and Easy Stepper, the relative signal names are: Enable,MS1,MS2,MS3,Reset,Sleep,Step,Direction use -1 if a pin is not used (i.e. strapped to a hard value with a wire)

Code: Select all

Motors = [(0,0x20,0,"FiveWire",0,1,2,3), (1,0x21,1,"A4988",0,1,2,3,4,5,6,7)]
The first value in the tuple in the list is the motor number, the second is the chip address for a 23017, the third is GPIOA or GPIOB on the chip, and the following digits are the mapping bits for the controller signals.

During initialization, I wish to create processes addressable by motor number and address/pipe/map/what-have-you commands and results to/from each child process. I would prefer each process to only receive motor data intended for it, but could tolerate a "that is not for me, ignore" sub-process handling. In the spirit of open computing, I will publish the full results. I had to generalize my setup due to a mix of motor types, chip configuration, etc. As you may be able to tell, I did this to easily define other types of control structures (if there really are any) and devices that can be made to communicate through the 23017 chip.

Re: Motor based multiprocessing

Posted: Mon Nov 16, 2015 3:35 pm
by -rst-
'Processes' sort of 'smells' like threads (https://docs.python.org/2/library/threading.html) and the rest is kind of screaming for classes (https://docs.python.org/2/tutorial/classes.html). To keep all the classes and threads in control look at creating a dictionary of motor objects (based on a motor class) with the numbers as keys.

Re: Motor based multiprocessing

Posted: Mon Nov 16, 2015 5:52 pm
by Tad Hasse
Thank you very much! A prod in the right direction is what I was looking for. I had things working with a pile of spagetti code and discrete variables, but maintaining it due to minor changes was looking to be a nightmare. For this section of the project, I hope my efforts help someone down the road who "just wants to make a bunch of motors go"