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 the LED light periodically.

Parameters
  • color (str, optional) – Color of the LED light. r, y or g. Defaults to all.

  • on_delay (float, optional) – Delay time for turned-on status. on_delay must be between 0.0 to 65.0 in second. Defaults to 0.256.

  • off_delay (float, optional) – Delay time for turned-off status. off_delay must be between 0.0 to 65.0 in second. Defaults to 0.256.

off(color='all')[source]

Turn off the LED light

Parameters

color (str, optional) – Color of the LED light. r, y or g. Defaults to all.

on(color='all')[source]

Turn on the LED light.

Parameters

color (str, optional) – Color of the LED light. r, y or g. Defaults to all.

toggle(color='all')[source]

Toggle the LED light. Turn off while the light on status and turn on while the light off.

Parameters

color (str, optional) – Color of the LED light. r, y or g. Defaults to all.

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.

connect()[source]

Connect to the module.

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_id()[source]

Get ID of the connected module.

Returns

Module ID.

Return type

int

get_serial_no()[source]

Get serial number of the connected module.

Returns

Serial number.

Return type

str

get_time()[source]

Get device time of the connected module.

Returns

Device time.

Return type

datetime

send(data)[source]

Send the data to the module

Parameters

data (bytearray of int) – Data to send.

set_default_switch_operation(on)[source]

Set either turn default switch operation on or not. Motor is spinning when switch is pressed by default.

Parameters

on (bool) – Set default operation on or off.

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 and rad/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 between 0.0 to 65.0 in second. Defaults to None.

  • unit (str, optional) – Speed unit must be one of rpm, deg/s and rad/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 {}.

stop()[source]

Stop the motor immediately.

class dynamikontrol.Motor.Motor(module)[source]

Bases: object

angle(*args, **kwargs)[source]
get_offset(*args, **kwargs)[source]
get_speed(*args, **kwargs)[source]
set_offset(*args, **kwargs)[source]
speed(*args, **kwargs)[source]
stop(*args, **kwargs)[source]
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 to 85 in degrees.

  • period (float, optional) – Control period. period must be between 0.0 to 65.0 in second. Defaults to None.

  • 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 {}.

get_offset()[source]

Get offset of the motor.

Returns

Offset of the motor in degree.

Return type

float

set_offset(angle)[source]

Set offset of the motor. If the motor angle is inclined slightly even angle set to 0, you can adjust offset of the motor manually.

Parameters

angle (float) – Offset of the motor in degree. e.g) 17.5

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 or 1. Defaults to 0.

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 or 1. Defaults to 0.

press(*args, **kwargs)[source]

Define callback function when switch is pressed. Exactly same as on method.

release(*args, **kwargs)[source]

Define callback function when switch is released. Exactly same as off method.

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 to None.

  • interval ([type], optional) – Callback interval time in seconds. Defaults to None.

stop()[source]

Stop the timer.

Module contents