Command Devices Package

This is the documentation for the Arduino devices that can be controlled with the Commanduino library. For more information on Axis control, please see the Devices Package. Here is a list of all supported devices:

For registering each device, please see the Register Module

Module contents

Custom package for managing different Arduino devices to be used in the Commanduino Library.

Command Analog Read Module

class commanduino.commanddevices.commandanalogread.CommandAnalogRead[source]

Bases: commanduino.commanddevices.commanddevice.CommandDevice

AnalogRead Arduino device.

Base:
CommandDevice
handle_level_command(*arg)[source]

Handles the level command.

Args:
*arg: Variable Argument.
register_all_requests()[source]

Registers all requests to the device.

Command Analog Write Module

class commanduino.commanddevices.commandanalogwrite.CommandAnalogWrite[source]

Bases: commanduino.commanddevices.commanddevice.CommandDevice

AnalogWrite Arduino device.

Base:
CommandDevice
set_pwm_value(value)[source]

Sets the pwm value.

Args:
value: The value to set.

Command Device Module

class commanduino.commanddevices.commanddevice.CommandDevice[source]

Bases: object

Base class to represent the different Arduino devices.

classmethod from_config(config)[source]

Obtains the device information from a configuration setup.

Returns:
CommandDevice: A new instance of CommandDevice with details set from the configuration.
handle_command(cmd)[source]

Handles a command to the device.

Args:
cmd (str): The command to handle.
init()[source]

Note

This function is called once the write function is set. Do your setup here by sending command to the devices

register_request(request_command, answer_command, variable_name, callback_function_for_variable_update, variable_init_value=None, timeout=1)[source]

Registers a new request to/from the device.

Args:

request_command (str): The requesting command.

answer_command (str): The answering command.

variable_name (str): The name of the variable.

callback_function_for_variable_update (str): The callback function for updating the variable.

variable_init_value: Initialisation value for the variable, default set to None.

timeout (float): Time to wait until timeout, default set to DEFAULT_TIMEOUT (1)

send(command_id, *arg)[source]

Sends a command to/from the device.

Args:

command_id (str): The ID of the command.

*arg: Variable argument.

set_command_header(cmdHeader)[source]

Sets the command header.

Args:
cmdHeader (str): The command header to be set.
set_write_function(write_func)[source]

Sets the write function for the device.

Args:
write_func (str): The write function to be set.
unrecognized(cmd)[source]

The supplied command is unrecognised.

Args:
cmd (str): The supplied command.
exception commanduino.commanddevices.commanddevice.CommandTimeOutError(device_name, command_name, elapsed)[source]

Bases: exceptions.Exception

Exception for when the device does not respond to a command after a set timeframe.

Args:

device_name (str): The name of the device.

command_name (str): The name of the command.

elapsed (float): Time elapsed until the exception was thrown.

exception commanduino.commanddevices.commanddevice.DeviceTimeOutError(device_name, elapsed)[source]

Bases: exceptions.Exception

Exception for when the device does not response within a set timeframe.

Args:

device_name (str): Name of the device.

elapsed (float): Time elapsed until the exception was thrown.

Command Digital Read Module

class commanduino.commanddevices.commanddigitalread.CommandDigitalRead[source]

Bases: commanduino.commanddevices.commanddevice.CommandDevice

DigitalRead Arduino device.

Base:
CommandDevice
handle_state_command(*arg)[source]

Handles the state setting command.

Args:
*arg: Variable command.
register_all_requests()[source]

Registers all requests.

Command Digital Write Module

class commanduino.commanddevices.commanddigitalwrite.CommandDigitalWrite[source]

Bases: commanduino.commanddevices.commanddevice.CommandDevice

DigitalWrite Arduino device.

Base:
CommandDevice
high()[source]

Sets the level to HIGH.

low()[source]

Sets the level to LOW.

set_level(level)[source]

Sets the level of the device.

Args:
level (int): The level setting.

Command Linear Accelerator Stepper Module

class commanduino.commanddevices.commandlinearaccelstepper.CommandLinearAccelStepper(speed=5000, max_speed=5000, acceleration=2000, homing_speed=2000, enabled_acceleration=True, reverted_direction=False, reverted_switch=False)[source]

Bases: commanduino.commanddevices.commanddevice.CommandDevice

Linear Aceclerator Stepper Arduino device.

Args:

speed (int): Speed of the device, default set to DEFAULT_SPEED (5000)

max_speed (int): Maximum speed of the device, default set to DEFAULT_MAX_SPEED (5000)

acceleration (int): Speed of acceleration, default set to DEFAULT_ACCELERATION (2000)

homing_speed (int): Himing speed of the device, default set to DEFAULT_HOMING_SPEED (2000)

enabled_acceleration (bool): Acceleration enabled, default set to True.

reverted_direction (bool): Direction is reverted, default set to False.

reverted_switch (bool): Switch is reverted, default set to False.

Base:
CommandDevice
apply_reverted_direction(value)[source]

Reverts the direction of movement.

Args:
value (int): The current value.
Returns:
value (int): The new value (-value)
disable_acceleration()[source]

Disables acceleration on the device.

disable_revert_switch()[source]

Disables switch revertion on the device.

enable_acceleration()[source]

Enables acceleration on the device.

enable_revert_switch()[source]

Enables switch revertion on the device.

handle_acceleration_command(*arg)[source]

Handles the command for acceleration.

Args:
*arg: Variable arguement.
handle_current_position_command(*arg)[source]

Handles the command for current position.

Args:
*arg: Variable command.
handle_distance_to_go_command(*arg)[source]

Handles the command for distance to go.

Args:
*arg: variable command.
handle_max_speed_command(*arg)[source]

Handles the command for maximum speed.

Args:
*arg: Variable argument.
handle_moving_state_command(*arg)[source]

Handles the command for moving state.

Args:
*arg: Variable command.
handle_speed_command(*arg)[source]

Handles the command for speed.

Args:
*arg: Variable command.
handle_switch_state_command(*arg)[source]

Handles the command for switch state.

Args:
arg*: Variable command.
handle_target_position_command(*arg)[source]

Handles the command for target position.

Args:
*arg: Variable command.
home(wait=True)[source]

Homes the device.

Args:
wait (bool): Wait for the device to be idle, default set to True.
init()[source]
is_moving

Check for movement in device.

Returns:
self.get_moving_state(): The movement state.
move(steps, wait=True)[source]

Moves the device a certain number of steps.

Args:

steps (int): The number of steps to move.

wait (bool): Waits for the device to be idle, default set to True.

move_to(steps, wait=True)[source]

Moves the device to a specific point.

Args:

steps (int): The position to move to.

wait (bool): Wait until the device is idle, default set to True.

print_info()[source]

Prints the current information for the device.

register_all_requests()[source]

Registers all requests to the device for later access.

set_acceleration(steps_per_second_per_second)[source]

Sets the acceleration speed of the device.

Args:
steps_per_second_per_second (int): The number of steps per second per second.
set_all_params()[source]

Sets all the parameters of the device automatically.

set_current_position(steps)[source]

Sets the current position of the device.

Args:
steps (int): The position to move to.
set_homing_speed(steps_per_second)[source]

Sets the homing speed of the device.

Args:
steps_per_second (int): The number of steps per second.
set_max_speed(steps_per_second)[source]

Sets the maximum speed of the device.

Args:
steps_per_second (int): The number of steps per second.
set_running_speed(steps_per_second)[source]

Sets the running speed of the device.

Args:
steps_per_second (int): The number of steps per second.
set_speed(steps_per_second)[source]

Sets the speed of the device.

Args:
steps_per_second (int): The number of steps per second to move.
stop(wait=True)[source]

Stops the movement of the device.

Args:
wait (bool): Wait until the device is idle, default set to True.
wait_until_idle()[source]

Waits until the device is idle (not moving).

Command Servo Module

class commanduino.commanddevices.commandservo.CommandServo[source]

Bases: commanduino.commanddevices.commanddevice.CommandDevice

Servo Arduino device.

handle_angle_command(*arg)[source]

Handles the command for the angle.

Args:
*arg: Variable argument.
register_all_requests()[source]

Registers all requests to the device for later use.

set_angle(angle)[source]

Sets the angle of the device.

Args:
angle (float): Angle to set the device to.

Register Module

exception commanduino.commanddevices.register.DeviceBonjourRegisterError(command_module_name)[source]

Bases: exceptions.Exception

Exception for handling when the Arduino device does not contain Bonjour ID and Class Name information.

exception commanduino.commanddevices.register.DeviceRegisterError(bonjour_id)[source]

Bases: exceptions.Exception

Exception for handling when the Bonjour ID is not in the register of the device.

commanduino.commanddevices.register.add_to_bonjour_register(bonjour_id, constructor)[source]

Adds the device to the Bonjour register.

Args:

bonjour_id (str): The Bonjour ID.

constructor: The constructor for registration.

commanduino.commanddevices.register.create_and_setup_device(cmdHdl, command_id, bonjour_id, device_config)[source]

Creates and sets up the Arduino device for usage.

Args:

cmdHdl (SerialCommandHandler): The Serial Command Handler object for serial communication.

command_id (str): The ID of the command.

bonjour_id (str): The Bonjour ID.

device_config (Dict): Dictionary containing the device configuration.

Raises:
DeviceRegisterError: Bonjour ID is not in the register of the device.