Skip to content

Commit

Permalink
unstable version bump to 0.0.17
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmf committed Feb 13, 2024
1 parent 8aed1da commit 1128eab
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 78 deletions.
Binary file modified doc/collab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
170 changes: 131 additions & 39 deletions doc/collab.puml
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
@startuml

note as N3 #grey
<size:22>**Color codes:**
<size:18><color APPLICATION >**INITIALIZATION** </color>
<size:18><color orange >**Your App will interact heavily with** </color>
<size:18><color LemonChiffon >**Your App might want to interact if complex** </color>
<size:18><color yellow >**Leaf implementations/Extension points. You might need to add sibling classes** </color>
end note

class BlockingQueueWorker {
startWorker()
killWorker()
}

class EventDispatcher <<Singleton>> #LemonChiffon {
multiprocessObserver: MultiprocessObserver
+ publishMainLoop(eventName, eventInfo)
+ register(eventName: list, callee): calleeId
+ unregister(calleeId)
+ getMultiprocessObserver()
+ {static} instance(multiprocessObserver=None)
- **_dispatchMainLoop()** // Worker job consumer
}

class MultiprocessObserver #LemonChiffon {
_eventObserver: Callable
_eventPublisher: Callable
observedEvent = Event()
observerLock = Lock()
--
+ {static} **eventObserver()** // Worker job consumer
+ {static} eventPublisher()
}
class UsesSingleThreadedExecutor
class ThreadPoolExecutorStackTraced

Expand All @@ -13,17 +42,22 @@ class ControllerFactory #APPLICATION {
}
class StaticControllerFactory
class DynamicControllerFactory
class MultiProcessingControllerFactory {
class MultiProcessingControllerFactory #Orange {
+setUpProcess()
+withDriver()
+spawn()
+spawn(): list[BipolarStepperMotorDriver] // proxies
-Unpacker.Unpack() // init Drivers \nin childProcess
}

class Navigation
class Navigation {
+ go()
+ {static} pulseController(motorDriver)
}
class StaticNavigation
class DynamicNavigation
class BasicSynchronizedNavigation
class BasicSynchronizedNavigation <<Singleton>> {
- **__doGo(pulsingController)** // Worker job consumer
}

class Benchmark #Orange {
findMinPps()
Expand All @@ -32,16 +66,45 @@ findTransformations() // Max Accelerations
}

class BipolarStepperMotorDriver #Orange{
signedSteps(steps, fn=None)
stepClockWise(steps, fn=None)
stepCounterClockWise(steps, fn=None)
- directionGpioPin
- stepGpioPin
- sleepGpioPin=None
- enableGpioPin=None
- stepsMode="Full"
- modeGpioPins=[]
- steppingCompleteEventName="steppingComplete"
## multiprocessing attributes:
- sharedMemory=None
- isProxy=False
--
+ signedSteps(steps, fn=None)
+ stepClockWise(steps, fn=None)
+ stepCounterClockWise(steps, fn=None)
+ pulseStart()
+ pulseStop()
- **_operateStepper()** // Worker job consumer
}

class DRV8825MotorDriver
class DRV8825MotorDriver #Yellow {
setSleepMode(sleepOn=False)
setEnableMode(enableOn=True)
pulseStart()
pulseStop()
}

class StepperMotor
class PG35S_D48_HHC2
class GenericStepper
class PG35S_D48_HHC2 #Yellow {
## DatasheetMax is 1500
LOADED_MAX_PPS = 900
LOADED_SLEEP = 1 / 900
NOLOAD_MAX_PPS = 800
NOLOAD_SLEEP = 1 / 800
}

class GenericStepper #Yellow {
maxPps
minPps
}

class AccelerationStrategy {
decreaseSleepTime()
Expand All @@ -67,63 +130,91 @@ class DelayPlanner {
}

class StaticDelayPlanner
class DynamicDelayPlanner
class DynamicDelayPlanner {
- state: State
}
class State {
effectSpeed()
+ effectSpeed()
+ transition()
}
class Rest <<Singleton>>
class RampingUp <<Singleton>>
class RampingDown <<Singleton>>
class Steady <<Singleton>>

mix_actor ClientApp

''' structure
ThreadPoolExecutorStackTraced --|> ThreadPoolExecutor
UsesSingleThreadedExecutor --|> ThreadPoolExecutorStackTraced
BlockingQueueWorker --|> UsesSingleThreadedExecutor
BipolarStepperMotorDriver ---|> BlockingQueueWorker
EventDispatcher -up-|> BlockingQueueWorker

PG35S_D48_HHC2 -up-|> StepperMotor
GenericStepper -up-|> StepperMotor

StaticControllerFactory -left-|> ControllerFactory
DynamicControllerFactory -left-|> ControllerFactory
SynchronizedControllerFactory -left-|> ControllerFactory
MultiProcessingControllerFactory -left-|> SynchronizedControllerFactory
StaticControllerFactory -up-|> ControllerFactory
DynamicControllerFactory -up-|> ControllerFactory
SynchronizedControllerFactory -up-|> ControllerFactory
MultiProcessingControllerFactory -down-|> SynchronizedControllerFactory

DRV8825MotorDriver -up-|> BipolarStepperMotorDriver

StaticDelayPlanner -down-|> DelayPlanner
DynamicDelayPlanner -up-|> DelayPlanner
DynamicDelayPlanner +-- State
DynamicDelayPlanner -down-|> DelayPlanner
DynamicDelayPlanner +-right- State

Rest -up--|> State
RampingUp -up-|> State
RampingDown -up--|> State
Steady -up-|> State
Rest -down--|> State
RampingUp -down-|> State
RampingDown -down--|> State
Steady -left-|> State

StaticNavigation -down-|> Navigation
DynamicNavigation -up-|> Navigation
BasicSynchronizedNavigation -up-|> Navigation
BasicSynchronizedNavigation -up-|> BlockingQueueWorker

LinearAcceleration ---|> AccelerationStrategy
ExponentialAcceleration --|> AccelerationStrategy
CustomAccelerationPerPps --|> AccelerationStrategy
InteractiveAcceleration ---|> AccelerationStrategy
DynamicNavigation -down-|> Navigation
BasicSynchronizedNavigation -down-|> Navigation
BasicSynchronizedNavigation -down-|> BlockingQueueWorker
MultiprocessObserver -up-|> BlockingQueueWorker
MultiprocessObserver "1 " -up-* EventDispatcher

LinearAcceleration -up--|> AccelerationStrategy
ExponentialAcceleration -up-|> AccelerationStrategy
CustomAccelerationPerPps -up--|> AccelerationStrategy
InteractiveAcceleration -up-|> AccelerationStrategy
BasicSynchronizedNavigation "\n 1" +-- "* " PulsingController
PulsingController *-- "1 \n" BipolarStepperMotorDriver

''' Relations
BipolarStepperMotorDriver -left-> Navigation
BipolarStepperMotorDriver -up-> AccelerationStrategy
BipolarStepperMotorDriver -right-> StepperMotor
EventDispatcher .down.> MultiprocessObserver : eventPublisher() / \n eventObserver()
BipolarStepperMotorDriver *-left- "1" Navigation
BipolarStepperMotorDriver *-up- "1" AccelerationStrategy
BipolarStepperMotorDriver *-down- " 1\n" StepperMotor

Navigation::go .down.> AccelerationStrategy::computeSleepTimeUs : computeSleepTimeUs()
Navigation .down.> BipolarStepperMotorDriver : pulseStart() \n pulseStop()
Navigation <.down. BipolarStepperMotorDriver : go()

Navigation .right.> AccelerationStrategy
AccelerationStrategy --> DelayPlanner
AccelerationStrategy *-up- "1" DelayPlanner

State ..> AccelerationStrategy : decreaseSleepTime()/\n increaseSleepTime()

Benchmark ..> InteractiveAcceleration

StaticControllerFactory .right.> StaticDelayPlanner
StaticControllerFactory .right.> StaticNavigation
StaticControllerFactory .down..> StaticDelayPlanner
StaticControllerFactory .down.> StaticNavigation

DynamicControllerFactory .down...> DynamicDelayPlanner
DynamicControllerFactory .down.> DynamicNavigation

SynchronizedControllerFactory .down...> DynamicDelayPlanner
SynchronizedControllerFactory *.down. "1" BasicSynchronizedNavigation

BipolarStepperMotorDriver .down.> EventDispatcher : publishMainLoop(\n"steppingComplete")

ClientApp *.right.. "n < 14\n(26 GPIO pins in RPi)" BipolarStepperMotorDriver
ClientApp .right.> BipolarStepperMotorDriver::signedSteps : signedSteps(-500, stepCallbackFn)
ClientApp <.right. BipolarStepperMotorDriver::operateStepper : stepCallbackFn(currentPosition, \ntargetPosition, \nrealDirection, \nmultiprocessObserver)

DynamicControllerFactory .right.> DynamicDelayPlanner
DynamicControllerFactory .right.> DynamicNavigation

''' Notes
note as N1
Expand All @@ -143,5 +234,6 @@ N1 .. Benchmark
N1 .. CustomAccelerationPerPps

N2 .. DynamicControllerFactory

@enduml

Binary file modified doc/multiprocess.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 25 additions & 19 deletions doc/multiprocess.puml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ class EventDispatcher as "EventDispatcher" <<Singleton>> {
+ register(eventName, callee)
- _waitChildProcessEvent()
}
class BlockingQueueWorkerEd as "BlockingQueueWorker" <<Instance>> {
+ work() // caller thread, puts in jobQueue
- _doConsumeJob(_waitChildProcessEvent: Callable) // pops jobQueue

class MultiprocessObserver {
_eventObserver: Callable
_eventPublisher: Callable
observedEvent = Event()
observerLock = Lock()
--
+ {static} eventObserver()
+ {static} eventPublisher()
}

abstract class MotorDriver1 as "MotorDriver" {
--
## stepping method arguments, [optional]
Expand All @@ -47,13 +54,13 @@ MotorDriver_Elevation_proxy ..> MotorDriver
MotorDriver_Azimuth_proxy ..> MotorDriver

class PolarCoordinatesSample <<User/Client code>> {
self.fireReadyEventsAwaited = ["azimuthAimingCompletesteppingCompleteAdvance",...]
self.elevationDriver // MainProcess driver proxy
self.azimuthDriver // MainProcess driver proxy
self.azimuthDriverEvent = Event()
self.elevationDriverEvent = Event()
self.azimuthEventsObserverWorker = None
self.elevationEventsObserverWorker = None
fireReadyEventsAwaited = ["azimuthAimingCompletesteppingCompleteAdvance",...]
elevationDriver // MainProcess driver proxy
azimuthDriver // MainProcess driver proxy
azimuthDriverEvent = Event()
elevationDriverEvent = Event()
azimuthEventsObserverWorker = None
elevationEventsObserverWorker = None
--
## waits on shared `multiprocess.Event` set by \n## sharedDataProcessing in P2
+ChildProcessEventObserver()
Expand Down Expand Up @@ -108,7 +115,7 @@ jobQueue // Shared multiprocess blocking queue

}
PolarCoordinatesSample .up.> MultiProcessingControllerFactory : 1) setUpProcess()\nwithDriver(<azimuth>)\nwithDriver(<elevation>)\nspawn()
PolarCoordinatesSample ..> EventDispatcher : register(["steppingCompleteAdvance",\n "steppingCompleteFinalStep",...], \n self.fireReadyEventHandler)
PolarCoordinatesSample ..> EventDispatcher : register(["steppingCompleteAdvance",\n "steppingCompleteFinalStep",...], \n fireReadyEventHandler)
MultiProcessingControllerFactory .right..> Process2

PolarCoordinatesSample ..> MotorDriver_Elevation_proxy : work()
Expand All @@ -122,14 +129,14 @@ MotorDriver_Azimuth ..> BasicSynchronizedNavigation: go(steps)
MotorDriver_Azimuth .up.> "EventDispatcher2" : publishMainLoop([prefix]+"steppingCompleteAdvance")\npublishMainLoop([prefix]+"steppingCompleteFinalStep")
MotorDriver_Azimuth .up.> PolarCoordinatesSample2 : sharedDataProcessing()

EventDispatcher ..> EventDispatcher : publishMainLoop() \n// Proxying child process events \n Notified with sharedMemory
EventDispatcher ..> PolarCoordinatesSample : notify("steppingCompleteAdvance")

MpQueue -up-|> multiprocess.Queue
EventDispatcher2 .up.> "set() \n" Event
BlockingQueueWorkerEd ..up..* EventDispatcher : <
BlockingQueueWorkerEd .left..> EventDispatcher : publishMainLoop("steppingCompleteAdvance" \n// proxyEventInChildPricess)
BlockingQueueWorkerEd .down..> "clear() \n" Event
MultiprocessObserver ..up..* EventDispatcher : <
MultiprocessObserver .left..> EventDispatcher : publishMainLoop("steppingCompleteAdvance" \n// proxyEventInChildPricess)
MultiprocessObserver .down..> "clear()\n set() \n\n" Event
MultiprocessObserver <.. EventDispatcher2 : eventPublisher()


note as N1
Proxy puts jobs in Queue but
Expand All @@ -138,9 +145,8 @@ end note

note as N2
EventDispatcher always notifies locally. Child Process'
ED also updates shared memory Values with event details
and signals with `process.Event.set()`.
MainProcess waits on process.Event to proxy events upstream
EventDispatcher also updates shared memory Values with
event details and MultiprocessObserver signals MainProcess
end note

N1 .up.> MotorDriver_Azimuth_proxy
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "hatchling.build"
[project]
name = "stepper_motors_juanmf1"
# I'll use the convention that even numbers are "stable" releases. Odd numbers need more testing.
version = "0.0.15"
version = "0.0.17"
authors = [
{ name="Juan Manuel Fernandez", email="[email protected]" },
]
Expand Down
1 change: 0 additions & 1 deletion src/stepper_motors_juanmf1/Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ def setEnableMode(self, enableOn=True):
tprint(f"Setting Enabled pin {self.enableGpioPin} to {state}")
GPIO.output(self.enableGpioPin, state)

@abstractmethod
def pulseStart(self):
"""
In most controllers this would mean set step pint to HIGH
Expand Down
11 changes: 0 additions & 11 deletions src/stepper_motors_juanmf1/Navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,6 @@ def pulseController(controller: MotorDriver):
controller.usleep(controller.PULSE_TIME_MICROS)
controller.pulseStop()

@staticmethod
def pulseControllerStart(controller):
# tprint(f"Setting step pin {controller.stepGpioPin} HIGH.")
controller.pulseStart()
return time.monotonic_ns()

@staticmethod
def pulseControllerStop(controller):
controller.pulseStop()
return time.monotonic_ns()

@staticmethod
def isInterruptible():
pass
Expand Down
7 changes: 0 additions & 7 deletions src/stepper_motors_juanmf1/StepperMotor.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,6 @@ def __init__(self, loaded: bool = True, minPps=210):


class GenericStepper(StepperMotor):
MIN_PPS = None
# Todo: remove this one

"""
Steps per Revolution with 1.8 deg per step
"""
SPR = 360 // 1.8

def __init__(self, *, maxPps, minPps=150):
super().__init__(maxPps, 1 / maxPps, minPps)

0 comments on commit 1128eab

Please sign in to comment.