コード例 #1
0
def gettouch(port) ->  int:
    global myEV3, stdscr
    ops_read = b''.join([
        ev3.opInput_Device,
        ev3.READY_SI,
        ev3.LCX(0),          # LAYER
        ev3.LCX(port),          # NO
        ev3.LCX(16),         # TYPE - EV3-Touch
        ev3.LCX(0),          # MODE - Touch
        ev3.LCX(1),          # VALUES
        ev3.GVX(0),          # VALUE1
        ev3.opInput_Device,
        ev3.READY_SI,
        ev3.LCX(0),          # LAYER
        ev3.LCX(1),          # NO
        ev3.LCX(16),         # TYPE - EV3-Touch
        ev3.LCX(1),          # MODE - Bump
        ev3.LCX(1),          # VALUES
        ev3.GVX(4)           # VALUE1
    ])
#    ops_sound = play_sound(10, 200, 100)
    reply = myEV3.send_direct_cmd(ops_sound + ops_read, global_mem=8)
#    return struct.unpack('<ff', reply[5:])
    (touched, bumps) = struct.unpack('<ff', reply[5:])
    if touched == 1:
        bumps += 0.5
#    print(bumps, "bumps")
    return bumps
	
	
コード例 #2
0
def stop() -> None:
    ops_read = b''.join([
        ev3.opInput_Device,
        ev3.READY_SI,
        ev3.LCX(0),  # LAYER
        ev3.LCX(2),  # NO
        ev3.LCX(125),  # TYPE - EV3-Touch
        ev3.LCX(0),  # MODE - Touch
        ev3.LCX(1),  # VALUES
        ev3.GVX(0),  # VALUE1
        ev3.opInput_Device,
        ev3.READY_SI,
        ev3.LCX(0),  # LAYER
        ev3.LCX(2),  # NO
        ev3.LCX(125),  # TYPE - EV3-Touch
        ev3.LCX(1),  # MODE - Bump
        ev3.LCX(1),  # VALUES
        ev3.GVX(4)  # VALUE1
    ])
    ops_sound = play_sound(10, 200, 100)
    reply = my_ev3.send_direct_cmd(ops_sound + ops_read, global_mem=8)
    (r, c) = struct.unpack('<ff', reply[5:])
    #    if touched == 1:
    #        bumps += 0.5
    print("color = ", c)
    print("refect = ", r)
コード例 #3
0
 def _drive(self, speed: int, turn: int, step: int) -> bytes:
     assert isinstance(speed, int), "speed needs to be an integer value"
     assert -100 <= speed and speed <= 100, "speed needs to be in range [-100 - 100]"
     if self._polarity == -1:
         speed *= -1
     if self._port_left < self._port_right:
         turn *= -1
     ops_ready = b''.join([
         ev3.opOutput_Ready,
         ev3.LCX(0),  # LAYER
         ev3.LCX(self._port_left + self._port_right)  # NOS
     ])
     ops_start = b''.join([
         ev3.opOutput_Step_Sync,
         ev3.LCX(0),  # LAYER
         ev3.LCX(self._port_left + self._port_right),  # NOS
         ev3.LCX(speed),
         ev3.LCX(turn),
         ev3.LCX(step),
         ev3.LCX(1),  # BRAKE
         ev3.opOutput_Start,
         ev3.LCX(0),  # LAYER
         ev3.LCX(self._port_left + self._port_right)  # NOS
     ])
     if self._sync_mode == ev3.SYNC:
         return self.send_direct_cmd(ops_start + ops_ready)
     else:
         return self.send_direct_cmd(ops_ready + ops_start)
コード例 #4
0
def play_sound(vol: int, freq: int, dur:int) -> bytes:
    return b''.join([
        ev3.opSound,
        ev3.TONE,
        ev3.LCX(vol),
        ev3.LCX(freq),
        ev3.LCX(dur)
    ])
コード例 #5
0
 def stop(self):  #-> None:
     ops = b''.join([
         ev3.opOutput_Stop,
         ev3.LCX(0),  # LAYER
         ev3.LCX(ev3.PORT_A + ev3.PORT_C),  # NOS
         ev3.LCX(0)  # BRAKE
     ])
     self.ev3.send_direct_cmd(ops)
コード例 #6
0
ファイル: Lego.py プロジェクト: jaekyun-Kang/AdaptiveSystems
def stop() -> None:
    global myEV3, stdscr

    ops = b''.join([
        ev3.opOutput_Stop,
        ev3.LCX(0),  # LAYER
        ev3.LCX(ev3.PORT_B + ev3.PORT_C),  # NOS
        ev3.LCX(0)  # BRAKE
    ])
    myEV3.send_direct_cmd(ops)
コード例 #7
0
def remote_motor_stop(port: int) -> None:
    global my_ev3
    ops = b''.join([
        ev3.opOutput_Stop,
        ev3.LCX(0),                       # LAYER
        ev3.LCX(port),                    # NOS
        ev3.LCX(0)                        # BRAKE
    ])
    my_ev3.send_direct_cmd(ops)
    print("Stop Remote MOTOR in PORT", port)
コード例 #8
0
ファイル: lego.py プロジェクト: markusvankempen/snp-2018
def stop() -> None:
    global myEV3, stdscr
    #    stdscr.addstr(5, 0, 'vehicle stopped                         ')
    ops = b''.join([
        ev3.opOutput_Stop,
        ev3.LCX(0),  # LAYER
        ev3.LCX(ev3.PORT_B + ev3.PORT_C),  # NOS
        ev3.LCX(0)  # BRAKE
    ])
    myEV3.send_direct_cmd(ops)
コード例 #9
0
def is_pressed(brick, port):
    cmd = b''.join([
        ev3.opInput_Read,
        ev3.LCX(0),
        ev3.LCX(port),
        ev3.LCX(16),
        ev3.LCX(0),
        ev3.GVX(0)
    ])
    return struct.unpack('<b',
                         brick.send_direct_cmd(cmd, global_mem=1)[5:])[0] > 0
コード例 #10
0
def go() -> None:
    ops_clear = b''.join([
        ev3.opInput_Device,
        ev3.CLR_CHANGES,
        ev3.LCX(0),  # LAYER
        ev3.LCX(1)  # NO
    ])
    ops_color = change_color(ev3.LED_GREEN_FLASH)
    ops_sound = play_sound(10, 200, 100)
    my_ev3.send_direct_cmd(ops_clear + ops_color + ops_sound)
    time.sleep(5)
コード例 #11
0
 def move_single_motor(self, motor):
     ops = b''.join([
         ev3.opOutput_Speed,
         ev3.LCX(0),  # LAYER
         ev3.LCX(motor['port']),  # NOS
         ev3.LCX(motor['speed']),  # SPEED
     ])
     self.ev3.send_direct_cmd(ops)
     if 'duration' in motor:
         if motor['duration'] > 0:
             time.sleep(motor['duration'])
             self.stop()
コード例 #12
0
 def read_infrared(self) -> float:
     ops = b''.join([
         ev3.opInput_Device,
         ev3.READY_SI,
         ev3.LCX(0),  # LAYER
         ev3.LCX(3),  # NO
         ev3.LCX(33),  # TYPE - EV3-IR
         ev3.LCX(0),  # MODE - Proximity
         ev3.LCX(1),  # VALUES
         ev3.GVX(0)  # VALUE1
     ])
     reply = self.send_direct_cmd(ops, global_mem=4)
     return struct.unpack('<f', reply[5:])[0]
コード例 #13
0
def remote_sensor_mode(port: int) -> None:
    global my_ev3

    ops = b''.join([
        ev3.opInput_Device,
        ev3.GET_TYPEMODE,
        ev3.LCX(0),                   # LAYER
        ev3.LCX(port),                # NO
        ev3.GVX(0),                   # TYPE
        ev3.GVX(1)                    # MODE
    ])
    reply = my_ev3.send_direct_cmd(ops, global_mem=2)
    (type, mode) = struct.unpack('BB', reply[5:7])
    print("Sensor Port: {} type: {}, mode: {}".format(port, type, mode))
コード例 #14
0
ファイル: lego.py プロジェクト: markusvankempen/snp-2018
def move(speed: int, turn: int) -> None:
    global myEV3, stdscr
    if speed > 50:
        spedd = 50


#    stdscr.addstr(5, 0, 'speed: {}, turn: {}      '.format(speed, turn))
    if turn > 0:
        speed_right = speed
        speed_left = round(speed * (1 - turn / 100))
    else:
        speed_right = round(speed * (1 + turn / 100))
        speed_left = speed
    ops = b''.join([
        ev3.opOutput_Speed,
        ev3.LCX(0),  # LAYER
        ev3.LCX(ev3.PORT_B),  # NOS
        ev3.LCX(speed_right),  # SPEED
        ev3.opOutput_Speed,
        ev3.LCX(0),  # LAYER
        ev3.LCX(ev3.PORT_C),  # NOS
        ev3.LCX(speed_left),  # SPEED
        ev3.opOutput_Start,
        ev3.LCX(0),  # LAYER
        ev3.LCX(ev3.PORT_B + ev3.PORT_C)  # NOS
    ])
    myEV3.send_direct_cmd(ops)
コード例 #15
0
def remote_motor_star(speed: int, port: int) -> None:
    global my_ev3

    ops = b''.join([
        ev3.opOutput_Speed,
        ev3.LCX(0),                       # LAYER
        ev3.LCX(port),              # NOS
        ev3.LCX(speed),             # SPEED
        ev3.opOutput_Start,
        ev3.LCX(0),                       # LAYER
        ev3.LCX(ev3.PORT_B)  # NOS
    ])
    my_ev3.send_direct_cmd(ops)
    print("Star Remote MOTOR in PORT",port)
コード例 #16
0
ファイル: Lego.py プロジェクト: jaekyun-Kang/AdaptiveSystems
def move_turn(speed: int, turn: int) -> None:
    global myEV3, stdscr

    if turn > 0:
        speed_right = speed
        speed_left = -speed

    else:

        speed_right = -speed
        speed_left = speed
        ops = b''.join([
            ev3.opOutput_Speed,
            ev3.LCX(0),  # LAYER
            ev3.LCX(ev3.PORT_B),  # NOS
            ev3.LCX(speed_right),  # SPEED
            ev3.opOutput_Speed,
            ev3.LCX(0),  # LAYER
            ev3.LCX(ev3.PORT_C),  # NOS
            ev3.LCX(speed_left),  # SPEED
            ev3.opOutput_Start,
            ev3.LCX(0),  # LAYER
            ev3.LCX(ev3.PORT_B + ev3.PORT_C)  # NOS
        ])
    myEV3.send_direct_cmd(ops)
コード例 #17
0
def distance(port) -> float:
    global myEV3, stdscr
    ops = b''.join([
        ev3.opInput_Device,
        ev3.READY_SI,
        ev3.LCX(0),          # LAYER
        ev3.LCX(port),          # NO
        ev3.LCX(33),         # TYPE - EV3-IR
        ev3.LCX(0),          # MODE - Proximity
        ev3.LCX(1),          # VALUES
        ev3.GVX(0)           # VALUE1
    ])
    reply = myEV3.send_direct_cmd(ops, global_mem=4)
    return struct.unpack('<f', reply[5:])[0]
コード例 #18
0
def move(speed: int, turn: int, claw: str) -> None:
    global myEV3, stdscr
    stdscr.addstr(
        5, 0, 'speed: {}, turn: {}, claw: {}      '.format(speed, turn, claw))
    if turn > 0:
        speed_right = speed
        speed_left = round(speed * (1 - turn / 100))
    else:
        speed_right = round(speed * (1 + turn / 100))
        speed_left = speed
    if claw == 'open':
        speed_claw = 50
    elif claw == 'stop':
        speed_claw = 0
    else:
        speed_claw = -50
    ops = b''.join([
        ev3.opOutput_Speed,
        ev3.LCX(0),  # LAYER
        ev3.LCX(ev3.PORT_A),  # NOS
        ev3.LCX(speed_right),  # SPEED
        ev3.opOutput_Speed,
        ev3.LCX(0),  # LAYER
        ev3.LCX(ev3.PORT_D),  # NOS
        ev3.LCX(speed_left),  # SPEED
        ev3.opOutput_Start,
        ev3.LCX(0),  # LAYER
        ev3.LCX(ev3.PORT_A + ev3.PORT_D)  # NOS
    ])
    myEV3.send_direct_cmd(ops)
コード例 #19
0
    def del_dir(self, path: str, secure: bool = True) -> None:
        """
        Delete a directory on EV3's file system

        Attributes:
        path: absolute or relative path (from "/home/root/lms2012/sys/")
        secure: flag, if the directory may be not empty
        """
        if secure:
            self.del_file(path)
        else:
            if path.endswith("/"):
                path = path[:-1]
            parent_path = path.rsplit("/", 1)[0] + "/"
            folder = path.rsplit("/", 1)[1]
            ops = b''.join([
                ev3.opFile, ev3.GET_FOLDERS,
                ev3.LCS(parent_path),
                ev3.GVX(0)
            ])
            reply = self.send_direct_cmd(ops, global_mem=1)
            num = struct.unpack('B', reply[5:])[0]
            found = False
            for i in range(num):
                ops = b''.join([
                    ev3.opFile,
                    ev3.GET_SUBFOLDER_NAME,
                    ev3.LCS(parent_path),
                    ev3.LCX(i + 1),  # ITEM
                    ev3.LCX(64),  # LENGTH
                    ev3.GVX(0)  # NAME
                ])
                reply = self.send_direct_cmd(ops, global_mem=64)
                subdir = struct.unpack('64s', reply[5:])[0]
                subdir = subdir.split(b'\x00')[0]
                subdir = subdir.decode("utf8")
                if subdir == folder:
                    found = True
                    ops = b''.join([
                        ev3.opFile,
                        ev3.DEL_SUBFOLDER,
                        ev3.LCS(parent_path),  # NAME
                        ev3.LCX(i + 1)  # ITEM
                    ])
                    self.send_direct_cmd(ops)
                    break
            if not found:
                raise ev3.DirCmdError("Folder " + path + " doesn't exist")
コード例 #20
0
 def read_color(self) -> float:
     ops = b''.join([
         ev3.opInput_Device,
         ev3.READY_SI,
         ev3.LCX(0),  # LAYER
         ev3.LCX(0),  # NO
         ev3.LCX(4),  # TYPE - EV3-IR
         ev3.LCX(2),  # MODE - Proximity
         ev3.LCX(1),  # VALUES
         ev3.GVX(0)  # VALUE1
     ])
     reply = self.send_direct_cmd(ops, global_mem=4)
     color = struct.unpack('<f', reply[5:])[0]
     if color not in (2, 3, 4, 5):
         color = 5
     return color
コード例 #21
0
 def get_degree_single_motor(self, motors, motor_num):
     ops = b''.join([
         ev3.opInput_Device,
         ev3.READY_SI,
         ev3.LCX(0),  # LAYER
         ev3.port_motor_input(motors[motor_num]['port']),  # NO
         ev3.LCX(7),  # TYPE
         ev3.LCX(0),  # MODE
         ev3.LCX(1),  # VALUES
         ev3.GVX(0),  # VALUE1
     ])
     reply = self.ev3.send_direct_cmd(ops, global_mem=8)
     pos = struct.unpack('<fi', reply[5:])
     print(pos)
     pos -= self.base_pos[motor_num]
     return pos
コード例 #22
0
def remote_gyro_input(port: int) -> int:
    global my_ev3
    ops = b''.join([
        ev3.opInput_Device,
        ev3.READY_SI,
        ev3.LCX(0),          # LAYER
        ev3.LCX(port),          # NO
        ev3.LCX(32),         # TYPE - EV3-IR
        ev3.LCX(0),          # MODE - Proximity
        ev3.LCX(1),          # VALUES
        ev3.GVX(0)           # VALUE1
    ])
    reply = my_ev3.send_direct_cmd(ops, global_mem=4)
    input = struct.unpack('<f', reply[5:9])[0] 
    print ("Remote GYRO input: {} in PORT: {}".format(input, port))
    return input
コード例 #23
0
def remote_motor_status(port: int) -> None:

    ops = b''.join([
        ev3.opInput_Device,
        ev3.READY_SI,
        ev3.LCX(0),                   # LAYER
        ev3.port_motor_input(port), # NO
        ev3.LCX(7),                   # TYPE
        ev3.LCX(0),                   # MODE
        ev3.LCX(1),                   # VALUES
        ev3.GVX(0),                   # VALUE1
    ])
    reply = my_ev3.send_direct_cmd(ops, global_mem=4)
    (pos_a,) = struct.unpack('<f', reply[5:])
#    pos_a = struct.unpack('<f', reply[5:])
    print("Get Remote MOTOR in PORT with position {}".format(pos_a))
コード例 #24
0
def cmd_tacho(port, var):
    return b''.join([
        ev3.opInput_Device, ev3.GET_RAW,
        ev3.LCX(0),
        ev3.port_motor_input(port),
        ev3.GVX(var)
    ])
コード例 #25
0
def cmd_waitdeg_wait(deg, waitport, tarvar, waitvar):
    return cmd_tacho(waitport, waitvar) + b''.join([
        ev3.opJr_Lt32 if deg > 0 else ev3.opJr_Gt32,
        ev3.GVX(waitvar),
        ev3.GVX(tarvar),
        ev3.LCX(-9)
    ])
コード例 #26
0
def cmd_waitdeg_target(deg, waitport, waitdeg, tarvar):
    return cmd_tacho(waitport, tarvar) + b''.join([
        ev3.opAdd32,
        ev3.GVX(tarvar),
        ev3.LCX(waitdeg if deg > 0 else -waitdeg),
        ev3.GVX(tarvar)
    ])
コード例 #27
0
    def move(self, speed: int, turn: int) -> None:
        """
        Start unlimited movement of the vehicle

        Arguments:
        speed: speed in percent [-100 - 100]
          > 0: forward
          < 0: backward
        turn: type of turn [-200 - 200]
          -200: circle right on place
          -100: turn right with unmoved right wheel
           0  : straight
           100: turn left with unmoved left wheel
           200: circle left on place
        """
        #assert self._sync_mode != ev3.SYNC, 'no unlimited operations allowed in sync_mode SYNC'
        assert isinstance(speed, int), "speed needs to be an integer value"
        assert -100 <= speed and speed <= 100, "speed needs to be in range [-100 - 100]"
        assert isinstance(turn, int), "turn needs to be an integer value"
        assert -200 <= turn and turn <= 200, "turn needs to be in range [-200 - 200]"
        # if self._polarity_left is -1:
        #     if turn >= 0:
        #         turn = 200 - turn
        #     else:
        #         turn = -200 - turn
        #         speed *= -1
        # if self._polarity_right is -1:
        #     if turn >= 0:
        #         turn = 200 - turn
        #         speed *= -1
        #     else:
        #         turn = -200 - turn
        if self._polarity is -1:
            speed *= -1
        if self._port_left < self._port_right:
            turn *= -1
        ops = b''.join([
            ev3.opOutput_Step_Sync,
            ev3.LCX(0),  # LAYER
            ev3.LCX(self._port_left + self._port_right),  # NOS
            ev3.LCX(speed),
            ev3.LCX(turn),
            ev3.LCX(0),  # STEPS
            ev3.LCX(0),  # BRAKE
            ev3.opOutput_Start,
            ev3.LCX(0),  # LAYER
            ev3.LCX(self._port_left + self._port_right)  # NOS
        ])
        reply = self.send_direct_cmd(ops + self._ops_pos(), global_mem=8)
        pos = struct.unpack('<ii', reply[5:])
        if self._port_left < self._port_right:
            turn *= -1
        self._update(pos)
        self._turn = turn
        self._speed = speed
        self._moves = True
コード例 #28
0
ファイル: lego.py プロジェクト: markusvankempen/snp-2018
def playsound() -> None:
    global myEV3
    ops = b''.join([
        ev3.opSound,
        ev3.PLAY,
        ev3.LCX(100),  # VOLUME
        ev3.LCS('./ui/DownloadSucces')  # NAME
    ])
    myEV3.send_direct_cmd(ops)
コード例 #29
0
def ultra(port):
    global lastUltra
    global curUltra
    if time() - lastUltra < 0.5:
        return curUltra
    ops = b''.join([
        ev3.opInput_Device,
        ev3.READY_SI,
        ev3.LCX(0),  # LAYER
        ev3.LCX(port),  # NO
        ev3.LCX(30),  # TYPE - EV3-IR
        ev3.LCX(0),  # MODE - Proximity
        ev3.LCX(1),  # VALUES
        ev3.GVX(0)  # VALUE1
    ])
    reply = my_ev3.send_direct_cmd(ops, global_mem=4)
    lastUltra = time()
    curUltra = struct.unpack('<f', reply[5:])[0]
    return curUltra
コード例 #30
0
ファイル: Lego.py プロジェクト: jaekyun-Kang/AdaptiveSystems
def pick(speed: int, turn: int) -> None:
    global myEV3, stdscr

    if turn > 0:
        speed_right = speed
        speed_left = round(speed * (1 - turn / 100))
    else:
        speed_right = speed
        speed_left = speed
    ops = b''.join([
        ev3.opOutput_Speed,
        ev3.LCX(0),  # LAYER
        ev3.LCX(ev3.PORT_A),  # NOS
        ev3.LCX(speed_right),  # SPEED
        ev3.opOutput_Start,
        ev3.LCX(0),  # LAYER
        ev3.LCX(ev3.PORT_A)  # NOS
    ])
    myEV3.send_direct_cmd(ops)