Exemple #1
0
async def listen_blender():
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.bind(('0.0.0.0', 8019))
    sock.listen(5)
    sock.settimeout(0.1)

    conn = None
    while conn is None:
        try:
            conn, addr = sock.accept()
        except socket.timeout:
            await asyncio.sleep(0.1)

    while True:
        try:
            rawData = str(conn.recv(1024)).replace('\'', '"')
            rawData = rawData[2:len(rawData) - 1]
            data = json.loads(rawData)

            # Send data to onboard rover
            msg = ArmPosition()
            msg.joint_a = data['A']
            msg.joint_b = data['B']
            msg.joint_c = data['C']
            msg.joint_d = data['D']
            msg.joint_e = data['E']

            lcm_.publish('/ik_ra_control', msg.encode())

        except socket.timeout:
            await asyncio.sleep(0.1)
Exemple #2
0
def listen_blender():
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.bind(('0.0.0.0', 8019))
    sock.listen(5)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    conn, addr = sock.accept()

    while True:
        try:
            # conn, addr = sock.accept()
            rawData = conn.recv(1024).decode()
            data = json.loads(rawData)

            # Send data to onboard rover
            msg = ArmPosition()
            msg.joint_a = data['A']
            msg.joint_b = data['B']
            msg.joint_c = data['C']
            msg.joint_d = data['D']
            msg.joint_e = data['E']

            lcm_.publish('/ik_ra_control', msg.encode())

        except socket.error as exc:
            # print(exc)
            pass
Exemple #3
0
    def publish_config(self, config, channel):
        arm_position = ArmPosition()
        arm_position.joint_a = config[0]
        arm_position.joint_b = config[1]
        arm_position.joint_c = config[2]
        arm_position.joint_d = config[3]
        arm_position.joint_e = config[4]

        self.lcm_.publish(channel, arm_position.encode())
Exemple #4
0
    def cartesian_control_callback(self, channel, msg):
        if self.enable_execute:
            return

        cart_msg = IkArmControl.decode(msg)
        delta = [cart_msg.deltaX, cart_msg.deltaY, cart_msg.deltaZ]

        joint_angles, is_safe = self.solver.IK_delta(delta, 3)

        if is_safe:
            arm_position = ArmPosition()
            arm_position.joint_a = joint_angles["joint_a"]
            arm_position.joint_b = joint_angles["joint_b"]
            arm_position.joint_c = joint_angles["joint_c"]
            arm_position.joint_d = joint_angles["joint_d"]
            arm_position.joint_e = -joint_angles["joint_e"]
            self.state.set_angles(arm_position)
            self.solver.FK(self.state)
            self.publish_transforms(self.state)
            if self.sim_mode:
                self.lcm_.publish('/arm_position', arm_position.encode())
            else:
                self.lcm_.publish('/ik_ra_control', arm_position.encode())
def listen_blender():
    global ik_mode
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.bind(('0.0.0.0', 8019))
    sock.listen(5)
    conn, addr = sock.accept()

    while True:
        try:
            # conn, addr = sock.accept()
            rawData = conn.recv(1024).decode()
            try:
                data = json.loads(rawData)
            except:
                continue

            diff_count = 0
            if prev_messages[0] is None:
                diff_count = NUM_PREV_MESSAGES
            else:
                for pd in prev_messages:
                    for i in range(5):
                        j = chr(ord('A') + i)
                        if pd is None or prev_messages[0][j] != pd[j]:
                            diff_count += 1
                            break

            prev_messages.pop(0)
            prev_messages.append(data)

            if diff_count <= 1:
                continue

            # Send data to onboard rover
            msg = ArmPosition()
            msg.joint_a = -data['A']
            msg.joint_b = -data['B']
            msg.joint_c = -data['C']
            msg.joint_d = -data['D']
            msg.joint_e = -data['E']

            lcm_.publish('/ik_ra_control', msg.encode())

        except socket.error as exc:
            print(exc)
            pass