Actuators¶
Motor controller¶
A motor contoller could use a motor object for driving a motor using rpm values.
-
class
pidevices.
Motor
(v_spec, rpm_spec, voltage)¶ Abstract class for a motor.
- Parameters
v_spec – Voltage specification, at no load state
rpm_spec – Rpm specification for v_spec at no load state
voltage – The power suply voltage.
-
property
voltage
¶ Voltage in use.
-
property
rpm
¶ Max rpm value given the voltage in use.
-
set_parameters
(voltage)¶ Set the voltage and compute the new max rpm value at no load-state.
- Parameters
voltage – The power suply voltage.
Dfrobot motor controller¶
-
class
pidevices.
DfrobotMotorController
(E1, M1, E2, M2, motor_1=None, motor_2=None, name='', max_data_length=0)¶ Dfrobot motor controller implementation using hwpm pins. Extends
MotorController
.- Parameters
E1 (int) – The pwm pin number of the first pwm channel.
M1 (int) – Pin number of first direction pin.
E2 (int) – The pwm pin number of the second pwm channel.
M2 (int) – Pin number of second direction pin.
motor_1 – Optional instance of a motor object. Defaults to none.
motor_2 – Optional instance of a motor object. Defaults to none.
-
property
E1
¶ Pin number of first pwm channel.
-
property
E2
¶ Pin number of second pwm channel.
-
property
M1
¶ Pin number of first direction pin.
-
property
M2
¶ Pin number of second direction pin.
-
property
frequency
¶ Frequency of pwm channels.
-
property
motor_1
¶ Motor 1 instance.
-
property
motor_2
¶ Motor 2 instance.
-
start
()¶ Initialize hardware and os resources.
-
write
(speed_1=None, speed_2=None, RPM=False)¶ Change motor’s speed.
- Parameters
speed_1 – Channel 1 speed. The value could be pwm duty cycle or rpm. Also for backward movement the value should be negative.
speed_2 – Channel 2 speed. The value could be pwm duty cycle or rpm. Also for backward movement the value should be negative.
RPM (boolean) – Flag stating the mode of the speed values. Defaults to
False
.
-
stop
()¶ Clear hardware and os resources.
-
class
pidevices.
DfrobotMotorControllerPCA
(bus, E1, M1, E2, M2, motor_1=None, motor_2=None, name='', max_data_length=0)¶ Dfrobot motor controller implementation using pca9685 driver. Extends
MotorController
.TODO: To be a composite device.
- Parameters
E1 (int) – The pwm channel of the first pwm channel.
M1 (int) – The pwm channel of the first direction pin.
E2 (int) – The pwm channel of the second pwm channel.
M2 (int) – The pwm channle of second direction pin.
motor_1 – Optional instance of a motor object. Defaults to none.
motor_2 – Optional instance of a motor object. Defaults to none.
-
property
bus
¶ Pin number of first pwm channel.
-
property
E1
¶ Pin number of first pwm channel.
-
property
E2
¶ Pin number of second pwm channel.
-
property
M1
¶ Pin number of first direction pin.
-
property
M2
¶ Pin number of second direction pin.
-
property
frequency
¶ Frequency of pwm channels.
-
property
motor_1
¶ Motor 1 instance.
-
property
motor_2
¶ Motor 2 instance.
-
start
()¶ Initialize hardware and os resources.
-
write
(speed_1=None, speed_2=None, RPM=False)¶ Change motor’s speed.
- Parameters
speed_1 – Channel 1 speed. The value could be pwm duty cycle or rpm. Also for backward movement the value should be negative.
speed_2 – Channel 2 speed. The value could be pwm duty cycle or rpm. Also for backward movement the value should be negative.
RPM (boolean) – Flag stating the mode of the speed values. Defaults to
False
.
-
stop
()¶ Clear hardware and os resources.
Servo driver¶
-
class
pidevices.
ServoDriver
(name='', max_data_length=100)¶ Class representing a servo driver. Extends
Actuator
.
PCA9685¶
-
class
pidevices.
PCA9685
(bus, frequency=None, oe=None, name='', max_data_length=1)¶ Class for controlling pca9685 led/servo driver. Extends
ServoDriver
Default address of the i2c slave address is 0x40 and 0x70 is for controlling all the pca9685 modules simultaneously if more than one is connected.
- Parameters
bus (int) – I2C bus.
frequency – PWM frequency of the module.
oe (int) – The bcm pin number of enable pin.
-
property
bus
¶ I2C bus.
-
property
oe
¶ BCM number of enable pin.
-
property
frequency
¶ Frequency of the pwm channels.
-
start
()¶ Init hardware and os resources.
-
write
(channels, values, degrees=False, delay=0)¶ Drive pwm channels.
- Parameters
channels – Could be a list of channels or just one channel, to drive all channels should be -1.
values – Could be a list of values one for every channel or just one value for all the channels. The type of the all values could be in duty cycle or angle in degrees.
degrees – Flag that states if the values is angle in degrees. Defaults to
False
.delay – Wait time until starting the on pulse. It is percentage of the number of module clock ticks.
- Raises
MoreValuesThanChannels – Error when the length of values list is bigger than the length of channels list.
-
stop
()¶ Free hardware and os resources.
Neopixel ledstrip¶
-
class
pidevices.
LedController
(led_count, led_pin, led_freq_hz, led_brightness, led_dma=10, led_invert=False, led_channel=0, led_strip=1050624, name='')¶ Implementation for the Neopixel Programmable RGB LEDS. Extends
Actuator
.It use’s rpi_ws281x library.
- Parameters
led_count (int) – Number of leds.
led_pin (int) – GPIO pin connected to the pixels.
led_freq_hz (int) – LED signal frequency in hertz (usually 800khz)
led_brightness (int) – Set to 0 for darkest and 255 for brightest
led_dma (int) – DMA channel to use for generating signal. Defaults to
10
.led_invert (boolean) – True to invert the signal (when using NPN transistor level shift). Defaults to
False
.led_channel (int) – Set to ‘1’ for GPIOs 13, 19, 41, 45 or 53. Defaults to
0
.led_strip – Strip type and colour ordering. Defaults to
ws.WS2811_STRIP_RGB
.
-
property
led_count
¶ Number of leds.
-
property
led_pin
¶ GPIO pin connected to the pixels.
-
property
led_freq_hz
¶ LED signal frequency in hertz.
-
property
led_brightness
¶ Set to 0 for darkest and 255 for brightest.
-
property
led_dma
¶ DMA channel to use for generating signal.
-
property
led_invert
¶ True to invert the signal.
-
property
led_channel
¶ Set to ‘1’ for GPIOs 13, 19, 41, 45 or 53.
-
property
led_strip
¶ Strip type and color ordering.
-
start
()¶ Initialize hardware and os resources.
-
stop
()¶ Free hardware and os resources.
-
write
(data, wait_ms=50, wipe=False)¶ Write to the leds.
- Parameters
data – A list of lists of which each list corresponds to each led and the values are [red, green, blue, brightness].
wait_ms (int) – Optional argument that has to be set when wipe is
True
. Defaults to50
.wipe – Flag for writting to all leds at once.
-
close
()¶ Free hardware and os resources.
Speaker¶
-
class
pidevices.
Speaker
(dev_name='speaker', name='', max_data_length=0)¶ Class representing a usb speaker extends
Actuator
- Parameters
dev_name (str) – The alsa name of the device.
-
property
dev_name
¶ Alsa device name.
-
property
playing
¶ Flag indicating if the speaker is playing a sound
-
start
()¶ Initialize hardware and os resources.
-
write
(source, volume=50, times=1, file_flag=False)¶ Abstact method for driving an actuator which will be overloaded.
-
async_write
(source, volume=50, times=1, file_flag=False)¶ Async write data to the speaker. Actually it just plays a playback.
- Parameters
file_path – The file path of the file to be played. Currently it supports only wav file format.
volume – Volume percenatage
times – How many time to play the same file.
-
cancel
()¶ Cancel playaback
-
pause
(enabled=True)¶ Pause or resume the playback.
- Parameters
enabled (boolean) – If it
True
pauses the playback else it resumes it.
-
stop
()¶ Clean hardware and os reources.
Touch screen¶
-
class
pidevices.
TouchScreen
(name='', max_data_length=0)¶ Class representing a touch screen extends
Actuator
.-
start
()¶ Initialize hardware and os resources.
-
write
(file_path=None, time_enabled=None, touch_enabled=None, color_rgb=None, color_hex=None, options=None, multiple_options=False, time_window=None, text=None, show_image=False, show_color=False, show_video=False, show_options=False)¶ Write to the screen
- Parameters
file_path – Optional argument specifying the path of an image. Defaults to
None
.time_enabled – Time in secs specifying the duration of the preview.
touch_enabled – Enable touch mode.
color_rgb – Color in rgb value.
color_hex – Color in hex value.
options (list) – A list with the options text.
multiple_options (boolean) – Flag to preview multiple options.
time_window –
text – Single text for preview.
show_image (boolean) – Flag for showing an image.
show_color (boolean) – Flag for showing just color.
show_video (boolean) – Flag for showing a video.
show_options (boolean) – Flag for showing a menu with options.
- Raises
Exception –
-
stop
()¶ Clean hardware and os resources.
-