Actuators¶
Actuator¶
Biaxe¶
Biotens¶
- class crappy.actuator.biotens.Biotens(port='/dev/ttyUSB0', baudrate=19200)[source]¶
Open the connection, and initialise the Biotens.
Note
You should only use this class to communicate with the Biotens.
CM Drive¶
- class crappy.actuator.cmDrive.CM_drive(port='/dev/ttyUSB0', baudrate=9600)[source]¶
Open a new default serial port for communication with a CMdrive actuator.
- get_position()[source]¶
Search for the physical position of the motor.
- Returns
Physical position of the motor.
Fakemotor¶
- class crappy.actuator.fakemotor.Fake_motor(inertia: float = 0.5, torque: float = 0.0, kv: float = 1000, rv: float = 0.4, fv: float = 2e-05, sim_speed: float = 1, initial_speed: float = 0, initial_pos: float = 0, **kwargs)[source]¶
To run test programs without a physical actuator.
Note
A virtual motor driven by a voltage, you can set its properties with the args. It has the same methods as a real motor:
open()
,set_speed()
,get_speed()
,get_position()
.- __init__(inertia: float = 0.5, torque: float = 0.0, kv: float = 1000, rv: float = 0.4, fv: float = 2e-05, sim_speed: float = 1, initial_speed: float = 0, initial_pos: float = 0, **kwargs)[source]¶
Sets the instance attributes.
- Parameters
inertia (
float
, optional) – Inertia of the motor (kg.m²).torque (
float
, optional) – A torque applied on the axis (N.m).kv (
float
, optional) – The electrical constant of the motor (t/min/V).rv (
float
, optional) – The solid friction.fv (
float
, optional) – The fluid friction.sim_speed (
float
, optional) – Speed factor of the simulation.initial_speed (
float
, optional) – (rpm)initial_pos (
float
, optional) – (turns)
Motorkit pump¶
- class crappy.actuator.motorkit_pump.Motorkit_pump[source]¶
The Motorkit_pump actuator is meant for controlling two DC pumps and a valve using Adafruit’s DC hat for Raspberry Pi.
It is a basic actuator that can only inflate, deflate or do nothing. The communication with the hat is over I2C.
Note
May work on other boards than Raspberry Pi supporting I2C, assuming a proper wiring.
Oriental¶
- class crappy.actuator.oriental.Oriental(baudrate=115200, port='/dev/ttyUSB0', gain=14.285714285714285)[source]¶
To drive an axis with an oriental motor through a serial link.
The current setup moves at .07mm/min with “VR 1”.
- __init__(baudrate=115200, port='/dev/ttyUSB0', gain=14.285714285714285)[source]¶
Sets the instance attributes.
Pololu Tic¶
- class crappy.actuator.pololu_tic.Find_serial_number(serial_number: str)[source]¶
A class used for finding USB devices matching a given serial number, using the
usb.core.find()
method.
- class crappy.actuator.pololu_tic.Pololu_tic(steps_per_mm: float, current_limit: float, step_mode: Union[int, str] = 8, max_accel: float = 20, t_shutoff: float = 0, config_file: Optional[str] = None, serial_number: Optional[str] = None, model: Optional[str] = None, reset_command_timeout: bool = True, backend: str = 'USB', unrestricted_current_limit: bool = False, pin_function: Optional[Dict[str, str]] = None, pin_polarity: Optional[Dict[str, str]] = None)[source]¶
Class for controlling Pololu’s Tic stepper motor divers.
The Pololu_tic Actuator block is meant for controlling a Pololu Tic stepper motor driver. It can be driven in both speed and position. Several Tic models are supported. The length unit is the millimeter (mm), and time unit is the second (s).
Important
Only for Linux users: In order to drive the Tic, the appropriate udev rule should be set. This is done automatically when installing ticcmd, or can be done using the udev_rule_setter utility in
crappy
’s util folder. It is also possible to add it manually by running:$ echo "SUBSYSTEM==\"usb\", ATTR{idVendor}==\"1ffb\", MODE=\"0666\"" | sudo tee pololu.rules > /dev/null 2>&1
in a shell opened in
/etc/udev/rules.d
.- __init__(steps_per_mm: float, current_limit: float, step_mode: Union[int, str] = 8, max_accel: float = 20, t_shutoff: float = 0, config_file: Optional[str] = None, serial_number: Optional[str] = None, model: Optional[str] = None, reset_command_timeout: bool = True, backend: str = 'USB', unrestricted_current_limit: bool = False, pin_function: Optional[Dict[str, str]] = None, pin_polarity: Optional[Dict[str, str]] = None) → None[source]¶
Checks args validity, finds the right device, reads the current limit tables.
- Parameters
steps_per_mm (
float
) – The number of full steps needed for the motor to travel 1mm. This varies according to the motor model, and can be deduced from the datasheet or directly measured. This value is usually between 50 and 500.current_limit (
float
) – The maximum current the motor is able to withstand, in mA. It is usually around 1A for small stepper motors, and can go up to a few Amps. The maximum allowedcurrent_limit
value depends on the Tic model. The Tic 36v4 default maximum current limit can be increased using theunrestricted_current_limit
parameter.step_mode (
int
, optional) – Sets the number of microsteps used for driving the motor. This number is always a power of 2. The minimum number of microsteps is 1 (full steps), and the maximum depends on the Tic model. All models however support modes 1 to 8. The block manages speed and length conversions so that changing the step mode doesn’t affect the motor behaviour.max_accel (
float
, optional) – The maximum allowed acceleration for the motor, in mm/s². When asked to reach a given speed or position, the motor accelerates at this rate. It also corresponds to the maximum allowed deceleration. Usually doesn’t need to be changed.t_shutoff (
float
, optional) – ThePololu_tic
block features an auto-shutoff thread that deenergizes the motor after a period of t_shutoff seconds of inactivity. The timer counts in steps of 0.1s, which is thus the maximum precision for this setting. When set to 0, this feature is disabled and the motor remains energized until theclose()
method is called.config_file (
str
, optional) – The path of the config file to be loaded to the Tic. It only works ifbackend
is ‘ticcmd’. The config file contains some specific settings that can only be accessed this way using the ‘ticcmd’ backend. Not necessary for most applications.serial_number (
str
, optional) – The serial number of the Tic to be controlled. It must be given as astr
, and it is an 8-digits number. Allows to control the right device if several Tic of the same model are connected. Otherwise an error is raised.model (
str
, optional) –The model of the Tic to be controlled. Available models are:
'T825', 'T824', 'T500', 'N825', 'T249', '36v4'
Allows to control the right device if several Tic of different models are connected. Otherwise an error is raised.
reset_command_timeout (
bool
, optional) – Enables or disables the reset_command_timeout thread. It can only be disabled ifbackend
is ‘USB’. This thread pings the Tic every 0.5s, so that it doesn’t block due to a Command Timeout error. This feature is a safety to prevent the motor from running indefinitely if the USB connection is down, so it is better not to disable it. When disabled the Tic never raises Command Timeout errors, and a bit of memory if freed because of the thread not running.backend (
str
, optional) –The backend for communicating with the Tic. Available backends are:
'USB', 'ticcmd'
They both communicate over USB, but ‘ticcmd’ requires Pololu’s firmware to be installed. Some features are specific to each backend.
unrestricted_current_limit (
bool
, optional) – Enables or disables the unrestricted current limit feature. Only works ifbackend
is ‘USB’, and for the 36v4 Tic model. When disabled, the maximum current allowed is 3939mA. If enabled, it goes up to 9095mA. The Tic should however be cooled in order to withstand currents higher than 3939mA.pin_function (
dict
, optional) –Allows setting the Tic GPIO functions. It is a
dict
whose keys are the pin names, and values are the functions. Only works ifbackend
is ‘USB’. Only the pins indicated inpin_function
are set, the others are left in their previous state. The available pins are:'SCL', 'SDA', 'TX', 'RX', 'RC'
and can be set to:
'Default', 'Kill switch', 'Limit switch forward', 'Limit switch reverse'
The GPIO functions remain set as long as they are not changed by the user, so for a given setup it is only necessary to set them once.
pin_polarity (
dict
, optional) –Allows setting the polarity of the GPIOs used as switches. It is a
dict
, whose keys are the pin names, and values are the pin polarities. Only works ifbackend
is ‘USB’. Only the pins indicated inpin_function
are set, the others are left in their previous state. The available pins are:'SCL', 'SDA', 'TX', 'RX', 'RC'
and can be set to:
'Active high', 'Active low'
The GPIO polarities remain set as long as they are not changed by the user, so for a given setup it is only necessary to set them once.
Warning
current_limit
: If thecurrent_limit
setting is higher than the motor max current, there’s a risk of overheating and damaging the motor !
Note
steps_per_mm
: If you have to measure this value, it can be done easily following this procedure. Setsteps_per_mm
to spm (100 should be fine), andstep_mode
to sm (8 should be fine). Run a crappy program for moving the motor from position 0 to position p (a few tenth of millimeters should be fine). The motor will reach an actual position ap that can be measured. The actualsteps_per_mm
value aspm for this motor can be calculated as follows:aspm = spm * p / ap
step_mode
: Increasing the number of microsteps allows to reduce the noise, the vibrations, and improve the precision. However the more microsteps, the lower the maximum achievable speed for the motor. Chances that the motor misses microsteps are also higher when the number of microsteps is high.t_shutoff
: This functionality was originally added for long assays in temperature controlled environments, so that the motor doesn’t unnecessarily heat the setup when inactive. In other assays, it may still be useful for reducing the noise, the electromagnetic interference, or the energy consumption.serial_number
: Serial numbers can be accessed using the lsusb command in Linux shell, or runningticcmd --list
if ticcmd is installed. This number is also printed during__init__()
if only one device is connected andserial_number
isNone
.model
: The model is written on the Tic board, and can be accessed by runningticcmd --list
in a shell if ticcmd is installed. It is also printed during__init__()
if only one device is connected andmodel
isNone
.Pins settings: The pin functions and polarity can also be set independently from
crappy
before starting the assay, in the ticgui.
- get_position() → float[source]¶
Reads the current motor position.
- Returns
float
– The position in mm
- set_position(position: float, speed: Optional[float] = None) → None[source]¶
Sends a position command to the motor.
- Parameters
Note
speed
: The only way to reach a position at a given speed is to change the maximum speed. The Tic will try to accelerate to the maximum speed but may remain slower if it doesn’t have time to do so before reaching the given position.
Servostar¶
- class crappy.actuator.servostar.Servostar(device, baudrate=38400, mode='serial')[source]¶
To drive and configure a servostar variator through a serial connection.