Modules
biorobotics
Tickers
- class biorobotics.Ticker(timer: int, freq: float, callback: callable, enable_gc: bool = False, use_hardware_id: bool = False)[source]
Timed callback manager
BioRobotics hardware timer ISR abstraction. Compared to pyb.Timer:
Removing the need of explicit tim.callback(micropython.schedule())
Timely garbage collection set on a ticker with GC=Enable
Other timer related functions
Note: the ticker is not started on initialization!
Construct Ticker
- Parameters
timer – Number of the on-board hardware timer to use (start at 0)
freq – Frequency (in Hz) of the callback
callback – Callback to be attached to the timer
enable_gc – Set to True to disable general automatic garbage collection and instead run GC at the end of the user callback - This is recommended when the function is the loop() of the program
use_hardware_id – When set to True, the timer id is used as the id of an on-board timer. When set to False (default), the id is used to count over general purpose timers. The latter is useful to avoid conflicts with attached pins
Tic / Toc
SerialPC
- class biorobotics.SerialPC(channels: int)[source]
Create serial connection to send data asynchronously
Non-blocking serial TX over CN1 (ST-Link VCOM, UART3) on STM32 H743ZI2
On every .send(), a floating point value (4 bytes) for every channel is transmitted. The protocol is:
3 identifier header bytes
1 byte with the number of channels
4 bytes with the current runtime in microseconds
multiples of 4 bytes
Constructor
- Parameters
channels – Number of channels to send data over
AnlogIn
- class biorobotics.AnalogIn(pin: str)[source]
Read analog signal
Extension of ADC
Constructor
An error will be throws if the pin does not have an Analog-to-Digital converted connected.
- Parameters
pin – Name of a pin or Pin object
PWM
- class biorobotics.PWM(pin: str, freq: float = 1000)[source]
Pulse-Width Modulation interface
Main purpose of the class is to automatically select the correct timers and channels based on the target pin.
Constructor
An error is thrown if the pin is not connected to a timer channel.
- Parameters
pin – Name of the pin (either STM or Arduino name), or a Pin object directly
freq – PWM frequency
- Raises
ValueError – If the selected pin does not have a registered timer
Encoder
- class biorobotics.Encoder(pin_a: str, pin_b: str)[source]
Class to wrap around hardware timers used for motor encoders
The encoder takes two digital-in pins, A and B, which need to be connected to the same hardware timer. The encoder is always type X4.
The class also takes care of unwrapping the value. The returned value will continue indefinitely, ignoring the integer overflow.
Constructor
- Parameters
pin_a – Encoder pin A (name or Pin object)
pin_b – Encoder pin B (name or Pin object)
- Raises
ValueError – If any of the selected pins do not have a registered timer
ValueError – If the pins do not share the same timer
- counter() int[source]
Return pulse count
Pulse count has already been unwrapped, it will start at 0 and increase and decrease indefinitely (including going negative).
Note: the unwrap happens when calling this read function, so it is possible to miss an encoder wrap if the read function is called only very rarely.
pyb
Timer
- class pyb.Timer(timer_id: int, freq: Optional[float] = None, callback: Optional[Callable] = None, *args, **kwargs)[source]
Hardware timer class
Constructor
Calls self.init()
- Parameters
timer_id – Timer id (defined by hardware)
- callback(func: Optional[Callable])[source]
Set or clear the timer callback
Set func to None to clear the callback.
- channel(channel_number, mode=None, pin=None, *args, **kwargs)[source]
Initialize and/or return a TimerChannel
- counter(new_counter: Optional[int] = None) int[source]
Get or set timer counter
When in encoder _mode, this corresponds to the number of encoder pulses.
LED
- class pyb.LED(led_id: int)[source]
LED Class
Create LED instance
- Parameters
led_id – id of the LED
- intensity(value: Optional[int] = None) Optional[int][source]
Set _intensity through PWM, from 0 to 255
Does not work on our Nucleo! None of the LEDs are connected to a PWM pin. We don’t bother a universal value here.
Switch
Pin
- class pyb.Pin(pin_id: str, mode: int = 0, pull: int = 0, af: int = - 1)[source]
Hardware pin class
Constructor
- irq(handler: Optional[Callable] = None, trigger: Optional[int] = None, priority: int = 1, wake=None, hard=False)[source]
Create pin interrupt
trigger can be an OR combination of IRQ flags
UART
Functions
stm
stm package
- stm.USART_CR1
- stm.USART3
uart3br
utime
Functions
Module Info
BioRobotics package.
- author
Robert Roos <robert.soo@gmail.com>
- license
MIT, see license file or https://opensource.org/licenses/MIT
- created on
2021-01-08 16:13:00