batteria + robot v0.1
This commit is contained in:
parent
7eaa00e48b
commit
e291375c25
3 changed files with 63 additions and 3 deletions
16
batteria.py
16
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()
|
||||
|
|
|
|||
30
guida_funzionante_2.py
Normal file
30
guida_funzionante_2.py
Normal file
|
|
@ -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()}")
|
||||
20
robot.py
20
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,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue