Exemplo n.º 1
0
#behaviours = [teleop_keys_behaviour, escape_behaviour]
behaviours = [
    cruise_behaviour, usonic_escape_behaviour, bump_escape_behaviour,
    imu_escape_behaviour
]
arbitrator = Arbitrator(behaviours)

server = Server(host='192.168.1.101', port=65432)
server.start()

while True:
    try:
        sensor_readings = sensors.read_sensors()
        server.update(sensor_readings)
        for sensor_reading in sensor_readings:
            print(sensor_reading.name + " " + str(sensor_reading.value))
        command = arbitrator.arbitrate(sensor_readings)
        # print(arbitrator.get_winning_behaviour().name)
        base.do_motion_command(command)

        time.sleep(0.1)

    except KeyboardInterrupt:
        # teleop_keys_behaviour.stop()
        server.stop()
        break

command = MotionCommand()
base.do_motion_command(command)
Exemplo n.º 2
0
motor_controller = SmartCarMotorController()

front_left_ir_sensor = ProximitySensor(name='front_left_ir', pin=20)
front_right_ir_sensor = ProximitySensor(name='front_right_ir', pin=21)
front_ir_sensor = ProximitySensor(name='front_ir', pin=26)

sensors = [front_ir_sensor, front_left_ir_sensor, front_right_ir_sensor]

wheel_separation = 0.133
max_speed = 0.52

base = SmartCarRobotBase(wheel_separation, max_speed, motor_controller,
                         sensors)

cruise_behaviour = Cruise(0)
escape_behaviour = SmartCarEscape(1)

behaviours = [cruise_behaviour, escape_behaviour]

arbitrator = Arbitrator(behaviours)

while True:
    sensors = base.read_sensors()
    for sensor in sensors:
        print(sensor.name + " " + str(sensor.value))
    command = arbitrator.arbitrate(sensors)
    print(arbitrator.get_winning_behaviour().name)
    base.do_motion_command(command)
    time.sleep(0.1)