CB3 botcore
– CodeBot CB3 hardware interface¶
Core low-level module for CodeBot-CB3.
- The botcore module gives you direct access to all the hardware on the CodeBot CB3.
-
class
CB3.botcore.
Buttons
[source]¶ Access to pushbutton switches BTN-0 and BTN-1.
-
class
CB3.botcore.
CB_LEDs
[source]¶ Manage all the LEDs on CodeBot.
-
enc_emit
(b)[source]¶ Set both Encoder emitter LEDs (2-bit value).
- Parameters
b (int) – Binary value, 0=off, 1=left, 2=right, 3=both
-
ls
(b)[source]¶ Set all User Line Sensor marker LEDs to the given binary integer value, or list/tuple of bools.
- Parameters
b – int value used to set LEDs, from 0 to 31 (2 5-1), or
b – list of 5 bools. (see
botcore.CB_LEDs.user
for example)
-
prox
(b)[source]¶ Set both Proximity marker LEDs.
- Parameters
b – int binary value, 0=off, 1=left, 2=right, 3=both ; or,
b – list of 2 bools. (see
botcore.CB_LEDs.user
for example)
-
user
(b)[source]¶ Set all User Byte LEDs to the given binary integer value or list/tuple of bools.
- Parameters
b – int value used to set LEDs, from 0 to 255 (2 8-1) ; or,
b – list of 8 bools.
Example:
leds.user(0) # turn all User LEDs off leds.user(255) # turn all User LEDs on leds.user(0b10101010) # Alternating LEDs leds.user( [True, False, False, True, True, True, True, True] )
-
-
class
CB3.botcore.
Encoders
(leds)[source]¶ Manage the wheel encoders. This class demonstrates simple low-level sensing of encoders via ADC channels. Higher performance implementations are available in separate modules, such as
timed_encoders
.
-
class
CB3.botcore.
Expansion
[source]¶ Access to the Expansion Port
-
make_pwm
(pin, duty_cycle=0, frequency=50)[source]¶ Connect a PWM (pulse width modulation) peripheral to the specified pin. This can be used to control servos, or as a general-purpose oscillating output.
- Parameters
pin – The IO pin to use, for example pin.EXP_GPIO0
duty_cycle – duration pin is high during each period, with 65535 being 100%.
frequency – periodic oscillation frequency in Hz (cycles per second)
- Returns
The PWMOut object bound to specified pin.
- Return type
-
release_pwm
(pwm)[source]¶ Disconnect the internal PWM peripheral previously bound to a pin.
- Parameters
pwm – A PWM peripheral created with make_pwm()
-
set_servo
(pwm, position_pct)[source]¶ Set the position of a servo controlled with a PWM output. The PWM frequency must be 50Hz (default value of make_pwm()). Note: Many servos require position_pct value to exceed the ±100 range to reach their mechanical limits. Also an offset may be needed to center the servo.
- Parameters
pwm – A PWM output created with make_pwm().
position_pct – Desired servo position with “nominal” range -100 to +100. A value of 0 will “center” the servo.
-
-
class
CB3.botcore.
LineSensors
(leds)[source]¶ Manage the line sensors.
-
check
(thresh=1000, is_reflective=False)[source]¶ Fast check of all line sensors against threshold(s). Controls emitter also.
Return a tuple of values for all line sensors. By default these are bool values indicating presence of a line, based on given parameters. See below for alternate behavior based on parameter types.
- Parameters
- Returns
Collection of bool “line detected” values.
If thresh=0, returns raw ADC values (ints).
If is_reflective is an int value it is interpreted as thresh_upper, and the function returns -1,0,+1 for readings below/within/above thresholds.
- Return type
tuple [5]
-
-
class
CB3.botcore.
Motors
(i2c)[source]¶ Manage the Motors
-
class
CB3.botcore.
Proximity
(leds)[source]¶ Manage the proximity sensors
-
range
(samples=4, power=1, rng_low=0, rng_high=100)[source]¶ Scan proximity sensors and return 0-100% range for each. This function runs a successive approximation algorithm to find the minimum range at which an object is detected by each sensor independently.
- Parameters
- Returns
0-100 if object detected, or -1 if not.
If samples=1, returns bool (L, R) values.
Note: When samples=1 the rng_high value is not used. A single sample is taken at rng_low.
- Return type
tuple of (L, R) int proximity values
-