def __get_battery_info(self): """ Gets information about the battery from the robot. Currently only provides measured volts. Could produce later. """ ps = ev3.PowerSupply() self._measured_volts = ps.measured_volts
def get_battert_amperage(self): """Obtain the battery measured current in microAmps""" try: power_supply = ev3.PowerSupply() self.battery_amperage = power_supply.measured_current except Exception as theException: ev3_remoted.ev3_logger.critical( "Ev3RobotModel: Exception in routine get_battery_level() + " + str(theException)) self.battery_amperage = 0 return self.battery_amperage
def get_battery_level(self): """Obtain the battery level""" try: power_supply = ev3.PowerSupply() self.battery_level = power_supply.measured_voltage except Exception as theException: ev3_remoted.ev3_logger.critical( "Ev3RobotModel: Exception in routine get_battery_level() + " + str(theException)) self.battery_level = 0 return self.battery_level
def __init__(self, rightMortor, leftMortor): self.right_motor = rightMortor self.left_motor = leftMortor self.gyro_sensor = ev3.GyroSensor('in4') self.battery = ev3.PowerSupply() self._is_loop = True # 最新取得値 self.gyro_sensor_rate = 0 self.left_motor_position = 0 self.right_motor_position = 0 self.battery_voltage = 0 #mV
def update_server(self): to_access = "http://" + self.web_server_ip to_access = to_access + ":" + str(self.web_server_port) to_access = to_access + "/api/botinfo" to_provide = { "name": robot_name, "x_loc": self.coords[0], "y_loc": self.coords[1], "state": "TEMP", "battery_volts": ev3.PowerSupply().measured_volts, "bearing": self.send_bearing(self.bearing) } post_data = urllib.parse.urlencode(to_provide) try: urllib.request.urlopen( url='{}?{}'.format(to_access, post_data), data="TEMP=TEMP".encode() ) except: # noqa: E722 print("[update_server] Has failed - failed to connect to: " + to_access) # noqa: E501
def __init__(self, port, quite): self.host = socket.gethostbyname(socket.getfqdn()) self.port = port self.quite = quite self.__socket = None self.__started = False self.__peer_sock = None self.__peer_addr = None self.__leftMotor = ev3.LargeMotor('outD') self.__rightMotor = ev3.LargeMotor('outA') self.__smallMotor = ev3.MediumMotor('outC') self.__ir = ev3.InfraredSensor() self.__power = ev3.PowerSupply() self.__last_ping = 0 self.__last_ir = 0 self.__last_pwr = 0 self.__gear = 1
def __init__(self): self.right_motor = Motor('outA') self.left_motor = Motor('outC') self.tail_motor = Motor('outB') self.gyro_sensor = ev3.GyroSensor('in4') self.battery = ev3.PowerSupply()
# Add or subtract offset and clamp the value between -100 and 100 if dutyInt > 0: dutyInt = min(100, dutyInt + frictionOffset) elif dutyInt < 0: dutyInt = max(-100, dutyInt - frictionOffset) # Apply the signal to the motor FastWrite(motorDutyFileHandle, dutyInt) ######################################################################## ## One-time Hardware setup ######################################################################## # EV3 Brick powerSupply = ev3.PowerSupply() buttons = ev3.Button() # Gyro Sensor setup. Possibly make this more generic to better support more sensors. try: # Set LEGO gyro to Gyro Rate mode, if attached gyroSensor = ev3.GyroSensor() gyroSensor.mode = gyroSensor.MODE_GYRO_RATE gyroType = 'LEGO-EV3-Gyro' except: # Assume HiTechnic Gyro is attached if LEGO Gyro not found gyroSensor = ev3.Sensor(address="ev3-ports:in2") gyroType = 'HITECHNIC-NXT-Gyro' # Open gyro rate sensor value file gyroSensorValueRaw = open(gyroSensor._path + "/value0", "rb") # Touch Sensor setup
import sensor import motors import lineFollow from difreg import difreg from time import sleep import ev3dev.ev3 as ev sensor.setmodeSensorsLR(sensor.REFLECT) power = ev.PowerSupply() MAXTURNSPEED = 0 MINTURNSPEED = 0 DRIVESPEED = 0 def batteryState(): global MAXTURNSPEED global MINTURNSPEED global DRIVESPEED voltage = power.measured_voltage / 1000000 if voltage < 8.0: print("State of battery: ") print(" Under 8.0. Voltage at " + str(voltage)) MAXTURNSPEED = 300 MINTURNSPEED = 100 DRIVESPEED = 800 else: print("State of battery: ") print(" Over 8.0. Voltage at " + str(voltage)) MAXTURNSPEED = 300 * 0.7 MINTURNSPEED = 100