Example #1
0
class RaiseRightHand(Action):
    def __init__(self):
        super().__init__()
        self.m = Minidora(self_host='0.0.0.0',
                          minidora_host='minidora-v0-yayoi.local')

    def activate(self):
        # Called when action activated
        super().activate()

        smdata = ServoMotorData()
        smdata.arm.right = 1.0
        self.m.move_servo_motor(smdata)

    def update(self):
        # Called every frame while action is activated
        super().update()

    def deactivate(self):
        # Called when action deactivated
        super().deactivate()

        smdata = ServoMotorData()
        smdata.arm.right = 0.0
        self.m.move_servo_motor(smdata)
Example #2
0
    def __init__(self, localhost, remotehost):
        super(MinidoraEnv, self).__init__(10)
        self.client = Minidora(self_host=localhost, minidora_host=remotehost)

        self.image = None
        self.pose = None

        def update_camera(image):
            self.image = image

        def update_pose(pose):
            self.pose = pose

        self.image_thread = self.client.listen_to_camera(update_camera)
        self.pose_thread = self.client.listen_to_pose(update_pose)
Example #3
0
class RandomMove(Action):
    def __init__(self):
        super().__init__()
        self.m = Minidora(self_host='0.0.0.0', minidora_host='minidora-v0-yayoi.local')

    def activate(self):
        # Called when action activated
        super().activate()

        smdata = ServoMotorData()
        smdata.arm.left = 1.0
        smdata.arm.right = 1.0
        smdata.head.roll = 0.0
        self.m.move_servo_motor(smdata)
    
    def update(self):
        # Called every frame while action is activated
        super().update()

        if (random.random() < 0.005):
            smdata = ServoMotorData()
            smdata.arm.left = random.random()
            smdata.arm.right = random.random()
            self.m.move_servo_motor(smdata)

    def deactivate(self):
        # Called when action deactivated
        super().deactivate()

        smdata = ServoMotorData()
        smdata.arm.left = 0.0
        smdata.arm.right = 0.0
        smdata.head.roll = 0.0
        self.m.move_servo_motor(smdata)
Example #4
0
class MinidoraEnv(Environment):
    def __init__(self, localhost, remotehost):
        super(MinidoraEnv, self).__init__(10)
        self.client = Minidora(self_host=localhost, minidora_host=remotehost)

        self.image = None
        self.pose = None

        def update_camera(image):
            self.image = image

        def update_pose(pose):
            self.pose = pose

        self.image_thread = self.client.listen_to_camera(update_camera,
                                                         block=False)
        self.pose_thread = self.client.listen_to_pose(update_pose, block=False)

        while self.pose is None or self.image is None:
            continue

    def step(self, action):
        larm = action[0]
        rarm = action[1]
        lleg = action[2]
        rleg = action[3]

        servo = ServoMotorData()
        servo.arm.left = (larm / 2 + 0.5)
        servo.arm.right = (rarm / 2 + 0.5)
        self.client.move_servo_motor(servo)

        dc = DcMotorData()
        dc.wheel.left = lleg * 100
        dc.wheel.right = rleg * 100
        self.client.move_dc_motor(dc)

        observation = {
            'image': self.image,
            'pose': self.pose,
        }
        reward = 1
        done = None
        info = None

        return observation, reward, done, info

    def render(self):
        pass

    def reset(self):
        pass
Example #5
0
class MinidoraEnv(Environment):
    def __init__(self, localhost, remotehost):
        super(MinidoraEnv, self).__init__(10)
        self.client = Minidora(self_host=localhost, minidora_host=remotehost)

        self.image = None
        self.pose = None

        def update_camera(image):
            self.image = image

        def update_pose(pose):
            self.pose = pose

        self.image_thread = self.client.listen_to_camera(update_camera)
        self.pose_thread = self.client.listen_to_pose(update_pose)

        #while self.pose is None or self.image is None:
        #    continue

    def step(self, action):
        servo = ServoMotorData()
        if "armleft" in action: servo.arm.left = (action["armleft"] / 2 + 0.5)
        if "armright" in action:
            servo.arm.right = (action["armright"] / 2 + 0.5)
        if "headroll" in action: servo.head.roll = action["headroll"]
        if "headpitch" in action: servo.head.pitch = action["headpitch"]
        if "headyaw" in action: servo.head.yaw = action["headyaw"]
        self.client.move_servo_motor(servo)

        dc = DcMotorData()
        if "wheelleft" in action: dc.wheel.left = action["wheelleft"] * 100
        if "wheelright" in action: dc.wheel.right = action["wheelright"] * 100
        self.client.move_dc_motor(dc)

        observation = {
            'image': self.image,
            'pose': self.pose,
        }
        reward = 1
        done = None
        info = None

        return observation, reward, done, info

    def render(self):
        pass

    def reset(self):
        pass
Example #6
0
 def __init__(self):
     super().__init__()
     self.m = Minidora(self_host='0.0.0.0', minidora_host='minidora-v0-yayoi.local')
Example #7
0
import cv2
import time
import random
from minidora import Minidora
from minidora.servo_motor import ServoMotorData

m = Minidora(self_host='0.0.0.0', minidora_host='minidora-v0-yayoi.local')

if __name__ == "__main__":
    while (True):
        smdata = ServoMotorData()
        smdata.arm.left = 1.0
        smdata.arm.right = 1.0
        smdata.head.roll = 0.0
        m.move_servo_motor(smdata)
        time.sleep(10.0)