dynamikontrol package¶
Submodules¶
dynamikontrol.LED module¶
- class dynamikontrol.LED.LED(module)[source]¶
Bases:
object
LED submodule class.
from dynamikontrol import Module import time module = Module() module.led.blink(color='r') # blink red module.led.toggle(color='g') # toggle green while True: module.led.on(color='y') # turn on yellow time.sleep(0.1) module.led.off(color='y') # turn off yellow time.sleep(0.1) module.disconnect()
- Parameters
module (object) – Module object.
- blink(color='all', on_delay=0.256, off_delay=0.256)[source]¶
Blink the LED light periodically.
- Parameters
color (str, optional) – Color of the LED light.
r
,y
org
. Defaults toall
.on_delay (float, optional) – Delay time for turned-on status.
on_delay
must be between0.0
to65.0
in second. Defaults to0.256
.off_delay (float, optional) – Delay time for turned-off status.
off_delay
must be between0.0
to65.0
in second. Defaults to0.256
.
- off(color='all')[source]¶
Turn off the LED light
- Parameters
color (str, optional) – Color of the LED light.
r
,y
org
. Defaults toall
.
dynamikontrol.Module module¶
- class dynamikontrol.Module.Module(serial_no=None, debug=False)[source]¶
Bases:
object
Module class.
from dynamikontrol import Module module = Module(serial_no) # specify the module by serial number # Print module serial number print('Serial number: %s' % (module.get_serial_no(),) module.disconnect()
- Parameters
serial_no (str) – Specify serial number of the module.
debug (bool) – print debug messages.
- disconnect()[source]¶
Close the connection of the module. Must include
module.disconnect()
at the end of the code so that module can close connection properly.
- get_fw_version()[source]¶
Get firmware version of the connected module.
- Returns
Device firmware version.
- Return type
str
- get_serial_no()[source]¶
Get serial number of the connected module.
- Returns
Serial number.
- Return type
str
dynamikontrol.Motor module¶
- class dynamikontrol.Motor.BLDC(module)[source]¶
Bases:
object
BLDC(Speed) motor submodule class.
from dynamikontrol import Module import time module = Module() module.motor.speed(1000) time.sleep(5) module.motor.stop() module.disconnect()
- Parameters
module (object) – Module object.
- get_speed(func, unit='rpm')[source]¶
Get speed of the motor asynchronously.
from dynamikontrol import Module import time module = Module() module.motor.speed(4000, period=10) def get_speed_cb(speed): print('Current Speed', speed) for i in range(60): time.sleep(0.5) module.motor.get_speed(func=get_speed_cb) module.disconnect()
- Parameters
func (function) – Callback function when getting speed from the motor.
unit (str, optional) – Speed unit must be one of
rpm
,deg/s
andrad/s
. Defaults to'rpm'
.
- speed(speed, period=None, unit='rpm', func=None, args=(), kwargs={})[source]¶
Control speed of the motor.
- Parameters
speed (int) – If
speed > 0
spins along clockwise, otherwise spins along counter clockwise.period (int, optional) – Control period.
period
must be between0.0
to65.0
in second. Defaults toNone
.unit (str, optional) – Speed unit must be one of
rpm
,deg/s
andrad/s
. Defaults to'rpm'
.func (function, optional) – Callback function when motor has been stopped. Defaults to
None
.args (tuple, optional) – args for callback function. Defaults to
()
.kwargs (dict, optional) – kwargs for callback function. Defaults to
{}
.
- class dynamikontrol.Motor.Servo(module)[source]¶
Bases:
object
Servo(Angle) motor submodule class.
from dynamikontrol import Module import time module = Module() module.motor.angle(0) time.sleep(2) while True: module.motor.angle(45) time.sleep(2) def cb(string): print(string) module.motor.angle(-45, func=cb, args=('hello',)) # print 'hello' when motor stopped at -45 degree. time.sleep(2) module.disconnect()
- Parameters
module (object) – Module object.
- angle(angle, period=None, func=None, args=(), kwargs={})[source]¶
Control the angle of motor.
- Parameters
angle (int) – If
angle > 0
moves along clockwise, otherwise moves along counter clockwise.angle
must be between-85
to85
in degrees.period (float, optional) – Control period.
period
must be between0.0
to65.0
in second. Defaults toNone
.func (function, optional) – Callback function when motor has been stopped. Defaults to
None
.args (tuple, optional) – args for callback function. Defaults to
()
.kwargs (dict, optional) – kwargs for callback function. Defaults to
{}
.
dynamikontrol.Switch module¶
- class dynamikontrol.Switch.Switch(module)[source]¶
Bases:
object
Switch submodule class.
from dynamikontrol import Module import time module = Module() def callback(string, angle): print(string) module.motor.angle(angle) module.switch.press(callback, ('Switched to on', 85,)) module.switch.release(callback, ('Switched to off', 0,)) while True: time.sleep(1) module.disconnect()
- Parameters
module (object) – Module object.
- off(func, args=(), kwargs={}, ch=0)[source]¶
Define callback function when switch is set to
off
status.- Parameters
func (function) – Callback function.
args (tuple, optional) – args. Defaults to
()
.kwargs (dict, optional) – kwargs. Defaults to
{}
.ch (int, optional) – Switch channel number. Must be
0
or1
. Defaults to0
.
- on(func, args=(), kwargs={}, ch=0)[source]¶
Define callback function when switch is set to
on
status.- Parameters
func (function) – Callback function.
args (tuple, optional) – args. Defaults to
()
.kwargs (dict, optional) – kwargs. Defaults to
{}
.ch (int, optional) – Switch channel number. Must be
0
or1
. Defaults to0
.
dynamikontrol.Timer module¶
- class dynamikontrol.Timer.Timer[source]¶
Bases:
object
General timer class.
from dynamikontrol import Module, Timer import time t1 = Timer() t2 = Timer() module = Module() t1.callback_at(func=module.led.toggle, args=('r',), at='2021-03-02 19:46:30', interval=0.1) t2.callback_after(func=module.led.toggle, args=('g',), after=1, interval=0.1) time.sleep(5) t1.stop() t2.stop() module.disconnect()
- callback_after(func, args=(), kwargs={}, after=0, interval=None)[source]¶
Call the callback function after specific time.
- Parameters
func (function) – Callback function.
args (tuple, optional) – args. Defaults to
()
.kwargs (dict, optional) – kwargs. Defaults to
{}
.after (int, optional) – Callback delay time in seconds. Defaults to
0
.interval (int, optional) – Callback interval time in seconds. Defaults to
None
.
- callback_at(func, args=(), kwargs={}, at=None, interval=None)[source]¶
Call the callback function at specific time.
- Parameters
func (function) – Callback function.
args (tuple, optional) – args. Defaults to
()
.kwargs (dict, optional) – kwargs. Defaults to
{}
.at (datetime str, optional) – Callback time in datetime str. e.g)
2021-03-04 21:57:30
. Defaults toNone
.interval ([type], optional) – Callback interval time in seconds. Defaults to
None
.