diff --git a/batteria.py b/batteria.py index 6e856d5..1602b42 100644 --- a/batteria.py +++ b/batteria.py @@ -14,7 +14,7 @@ class Colors: NC: str = "\033[0m" -def calcola_carica(v_mv: float): +def calcola_carica(v_mv: float) -> str: v: float = v_mv / 1000 carica = "" if v >= 8.4: @@ -28,12 +28,24 @@ def calcola_carica(v_mv: float): return carica + Colors.NC +def calcola_perc(v_mv: float) -> float: + v: float = v_mv / 1000.0 + v_min: float = 6.8 + v_max: float = 8.5 + perc: float = (v - v_min) / (v_max - v_min) * 100.0 + if perc < 0.0: + return 0.0 + if perc > 100.0: + return 100.0 + return perc + + def print_carica(): v_mv = hub.battery.voltage() # millivolt i_ma = hub.battery.current() # milliampere (corrente assorbita) print(f"Voltage: {v_mv} mV | Current: {i_ma} mA") # print(f"Caricatore: {}") - print(f"Batteria: {calcola_carica(v_mv)}") + print(f"Batteria: {calcola_carica(v_mv)} ({calcola_perc(v_mv)}%)") print_carica() diff --git a/guida_funzionante_2.py b/guida_funzionante_2.py new file mode 100644 index 0000000..2f7544f --- /dev/null +++ b/guida_funzionante_2.py @@ -0,0 +1,30 @@ +from pybricks.hubs import PrimeHub +from pybricks.parameters import Axis, Direction, Port +from pybricks.pupdevices import Motor +from pybricks.robotics import DriveBase +from pybricks.tools import wait + +from robot import CBHUB as HUB + +# import batteria + +hub = HUB.hub +db = HUB.db + +db.use_gyro(True) +# (mm/s, mm/s², deg/s, deg/s²) +db.settings(100, 100, 90, 50) +wait(300) +db.reset(angle=0) + + +db.straight(100) +db.turn(90) +db.straight(100) +db.turn(90) +db.straight(100) +db.turn(90) +db.straight(100) +db.turn(90) + +print(f"drived {db.distance()}") diff --git a/robot.py b/robot.py index ca74d8a..c781201 100644 --- a/robot.py +++ b/robot.py @@ -55,7 +55,7 @@ class Robot: right_port: Port, left_direction: Direction, right_direction: Direction, - wheel_diameter: int, + wheel_diameter: float, axle_track: int, use_gyro: bool, straight_speed: int = DEFAULT_STRAIGHT_SPEED, @@ -110,3 +110,21 @@ LEOHUB: Robot = Robot( turn_acceleration=DEFAULT_TURN_ACCELERATION, settle_ms=DEFAULT_GYRO_SETTLE_MS, ) + +CBHUB: Robot = Robot( + name="cbhub", + top_side=A.UP, + front_side=A.RIGHT, + left_port=Port.B, + right_port=Port.A, + left_direction=Direction.COUNTERCLOCKWISE, + right_direction=Direction.CLOCKWISE, + wheel_diameter=49.5, + axle_track=88, + use_gyro=True, + straight_speed=DEFAULT_STRAIGHT_SPEED, + straight_acceleration=DEFAULT_STRAIGHT_ACCELERATION, + turn_rate=DEFAULT_TURN_RATE, + turn_acceleration=DEFAULT_TURN_ACCELERATION, + settle_ms=DEFAULT_GYRO_SETTLE_MS, +)