Beispiel #1
0
 def post(self, *args):
     eyes = Eyes()
     if args[0] == 'verify':
         result = eyes.get_order_by_id_number(self.get_argument("id_number"))
         if result:
             self.write(dict(code=200, info="OK"))
         else:
             self.write(dict(code=500, info="无法查询到该身份证号的预约记录!"))
Beispiel #2
0
 def post(self, *args):
     eyes = Eyes()
     if args[0] == 'verify':
         result = eyes.get_order_by_id_number(
             self.get_argument("id_number"))
         if result:
             self.write(dict(code=200, info="OK"))
         else:
             self.write(dict(code=500, info="无法查询到该身份证号的预约记录!"))
Beispiel #3
0
 def get(self, *args):
     eyes = Eyes()
     if args[0] == '':
         self.render('eyes/index.html')
     if args[0] == 'detail':
         if not self.get_argument("id_number", None):
             self.redirect('/eyes/')
         result = eyes.get_order_by_id_number(self.get_argument("id_number"))
         if not result:
             self.redirect('/eyes/')
         self.render('eyes/detail.html', result=result)
Beispiel #4
0
 def get(self, *args):
     eyes = Eyes()
     if args[0] == '':
         self.render('eyes/index.html')
     if args[0] == 'detail':
         if not self.get_argument("id_number", None):
             self.redirect('/eyes/')
         result = eyes.get_order_by_id_number(
             self.get_argument("id_number"))
         if not result:
             self.redirect('/eyes/')
         self.render('eyes/detail.html', result=result)
Beispiel #5
0
 def post(self, *args):
     eyes = Eyes()
     if args[0] == "eyes":
         new_order = {
             "id_number": self.get_argument("id_number"),
             "name": self.get_argument("name"),
             "sex": self.get_argument("sex"),
             "result": self.get_argument("result"),
             "time": self.get_argument("time"),
             "location": self.get_argument("location"),
             "doctor": self.get_argument("doctor")
         }
         self.write(eyes.create_order(new_order))
Beispiel #6
0
 def post(self, *args):
     eyes = Eyes()
     if args[0] == "eyes":
         new_order = {
             "id_number": self.get_argument("id_number"),
             "name": self.get_argument("name"),
             "sex": self.get_argument("sex"),
             "result": self.get_argument("result"),
             "time": self.get_argument("time"),
             "location": self.get_argument("location"),
             "doctor": self.get_argument("doctor")
         }
         self.write(eyes.create_order(new_order))
"""Beo's famous dance"""
from time import sleep
from Movements import Movements
from Eyes import Eyes
from Audio import Audio
from SensorTouch import SensorTouch

SENSORTOUCH = SensorTouch()
AUDIO = Audio()
EYES = Eyes()
MOVEMENTS = Movements()


def update_touch(dancing):
    """Checks to see if the sensor is being touched"""
    SENSORTOUCH.update_status()
    status = SENSORTOUCH.get_status()
    if status == 1:
        if dancing:
            return False
        else:
            return True
    else:
        return False


DANCING = False
while True:

    DANCING = update_touch(DANCING)
    if DANCING:
Beispiel #8
0
def play_episode(policy_net, target_net, agent_obj, memory, world_state,
                 optimizer, cfg, device, i_episode):
    print(i_episode)
    skip_sec_frame = 2
    reward_report = 0
    init = True
    action = 0
    ttr = 0
    time.sleep(1.5)
    if i_episode % 7 == 0 or TEST_FLAG:
        print("Testing best policy")
    last_dis = 99999
    print(i_episode)
    eyes = Eyes()

    while world_state.is_mission_running:
        current_r = 0
        reward_report += 1

        try:
            input_img_temp = get_img(world_state, agent_obj, eyes, device)
        except:
            import traceback
            traceback.print_exc()
            print("Skipped")
            world_state = agent_obj.agent_host.getWorldState()
            continue
        state = input_img_temp

        if i_episode % 7 == 0 or TEST_FLAG:
            print("Testing")
            policy_net.eval()
        else:
            policy_net.train()
        action = select_action(policy_net, state, cfg, device,
                               len(agent_obj.get_act_list()), i_episode)
        err = False
        for error in world_state.errors:
            print("Error:", error.text)
            err = True
        if err:
            break
        agent_obj.set_action(agent_obj.get_act_list()[action])
        time.sleep(0.05)

        world_state = agent_obj.agent_host.getWorldState()
        for reward in world_state.rewards:
            if reward.getValue() > 0:
                print("D!")
                if i_episode % 7 == 0:
                    if not TEST_FLAG:
                        torch.save(policy_net.state_dict(),
                                   "./saved_params_final.wts")
                else:
                    if i_episode > 35:
                        if not TEST_FLAG:
                            torch.save(policy_net.state_dict(),
                                       "./saved_params_train_final.wts")

            current_r += reward.getValue() + 0.0

        current_r += 7.5
        if action != 0:
            current_r -= 4.5
        ttr += current_r

        try:
            current_screen = get_img(world_state, agent_obj, eyes, device)
        except:
            continue

        current_r = torch.tensor([current_r], device=device).float()
        if world_state.is_mission_running:
            next_state = current_screen
        else:
            next_state = None

        if reward_report % 1 == 0:
            print(current_r.item())

        # if i_episode + 1 % 15 == 0:
        #     continue
        memory.push(state.cpu(), action, next_state, current_r)
        if i_episode % 7 == 0 or TEST_FLAG:
            continue
        else:

            optimize_model(memory, device, cfg, policy_net, target_net,
                           optimizer)

        #agent_obj.set_action(agent_obj.get_act_list()[random.randint(0, 4)])

        time.sleep(0.01)
    REWARDS.append(ttr)
    if i_episode % cfg.TARGET_UPDATE == 0:
        print("Target Updated.")
        target_net.load_state_dict(policy_net.state_dict())
    print("R=", ttr)

    with open("./data_saved.txt", "w") as f:
        f.write(str(REWARDS) + "\n" + str(LOSS))
Beispiel #9
0
def pickup(cfg):
    """
    Construct a working robotic vehicle from many parts.
    Each part runs as a job in the Vehicle loop, calling either
    it's run or run_threaded method depending on the constructor flag `threaded`.
    All parts are updated one after another at the framerate given in
    cfg.DRIVE_LOOP_HZ assuming each part finishes processing in a timely manner.
    Parts may have named outputs and inputs. The framework handles passing named outputs
    to parts requesting the same named input.
    """

    V = dk.vehicle.Vehicle()

    #    clock = Timestamp()
    #    V.add(clock, outputs=['timestamp'])

    cam = PiCamera(image_w=cfg.IMAGE_W,
                   image_h=cfg.IMAGE_H,
                   image_d=cfg.IMAGE_DEPTH)
    # for Emily's setup we need to flip the camera and change the shutter speed
    cam.camera.hflip = True
    cam.camera.vflip = True
    cam.camera.shutter_speed = 5000
    V.add(cam, inputs=[], outputs=['image'], threaded=True)

    inputs = []
    threaded = True
    from donkeycar.parts.camera import PiCamera
    cam = PiCamera(image_w=cfg.IMAGE_W,
                   image_h=cfg.IMAGE_H,
                   image_d=cfg.IMAGE_DEPTH)
    V.add(cam, inputs=inputs, outputs=['image'], threaded=threaded)

    #
    #    # get eyes
    model = Eyes(cfg.MODEL_CFG, cfg.MODEL_WEIGHTS, cfg.IMAGE_W, cfg.IMAGE_H)
    V.add(model, inputs=['image'], outputs=['bboxes'])
    #
    # get strategy
    strategy = Brains(pic_to_reality_csv=cfg.MAP_PATH)
    V.add(strategy,
          inputs=['bboxes'],
          outputs=[
              'angle', 'throttle', 'runtime', 'waittime', 'emily', 'emil', 'x',
              'y', 'emil3', 'emil3rest'
          ])

    print('steering channel ', cfg.STEERING_CHANNEL, ' throttle channel ',
          cfg.THROTTLE_CHANNEL)
    steering_controller = PCA9685(cfg.STEERING_CHANNEL,
                                  cfg.PCA9685_I2C_ADDR,
                                  busnum=cfg.PCA9685_I2C_BUSNUM)
    steering = PWMSteering(controller=steering_controller,
                           left_pulse=cfg.STEERING_LEFT_PWM,
                           right_pulse=cfg.STEERING_RIGHT_PWM)

    throttle_controller = PCA9685(cfg.THROTTLE_CHANNEL,
                                  cfg.PCA9685_I2C_ADDR,
                                  busnum=cfg.PCA9685_I2C_BUSNUM)
    throttle = PWMThrottle(controller=throttle_controller,
                           max_pulse=cfg.THROTTLE_FORWARD_PWM,
                           zero_pulse=cfg.THROTTLE_STOPPED_PWM,
                           min_pulse=cfg.THROTTLE_REVERSE_PWM)

    V.add(steering, inputs=['angle'], outputs=[], run_condition='emily')
    V.add(throttle, inputs=['throttle'], outputs=[], run_condition='emily')

    #    # add the stopper
    runner = Runner()
    V.add(runner, inputs=['runtime'], outputs=['throttle2'])
    #
    #    # add second throttle
    throttle2 = PWMThrottle(controller=throttle_controller,
                            max_pulse=cfg.THROTTLE_FORWARD_PWM,
                            zero_pulse=cfg.THROTTLE_STOPPED_PWM,
                            min_pulse=cfg.THROTTLE_REVERSE_PWM)
    V.add(throttle2, inputs=['throttle2'], outputs=[], run_condition='emily')
    #
    #    # add the stopper
    runner2 = Runner()
    V.add(runner2, inputs=['waittime'], outputs=['throttle2'])
    #
    #    # get Emil
    #    emil = Emil([0,1,2,3], cfg.PCA9685_I2C_ADDR, busnum=cfg.PCA9685_I2C_BUSNUM)
    emil3_controller = PCA9685(3,
                               cfg.PCA9685_I2C_ADDR,
                               busnum=cfg.PCA9685_I2C_BUSNUM)
    emil3 = Emil(emil3_controller, 1.0)
    V.add(emil3, inputs=['emil3'], outputs=[], run_condition='emil')

    V.add(emil3, inputs=['emil3rest'], outputs=[], run_condition='emil')
    #
    if cfg.PUB_CAMERA_IMAGES:
        pub = TCPServeValue("camera")
        V.add(ImgArrToJpg(), inputs=['image'], outputs=['jpg/bin'])
        V.add(pub, inputs=['jpg/bin'], outputs=[])


#
#    # add tub to save data
    inputs = ['image', 'angle', 'throttle']
    types = ['image_array', 'float', 'float']
    #
    #    # multiple tubs
    th = TubHandler(path=cfg.DATA_PATH)
    tub = th.new_tub_writer(inputs=inputs, types=types)
    #
    #    # single tub
    #    # tub = TubWriter(path=cfg.TUB_PATH, inputs=inputs, types=types)
    V.add(tub, inputs=inputs, outputs=["tub/num_records"])
    #
    # run the vehicle
    V.start(rate_hz=cfg.DRIVE_LOOP_HZ, max_loop_count=cfg.MAX_LOOPS)
"""Activates arm mirror, changes eyes and says a short sentence every few seconds"""
from time import sleep
from random import randint
import subprocess
import threading
from Movements import Movements
from Audio import Audio
from Eyes import Eyes

MOVEMENTS = Movements()
AUDIO = Audio()
EYES = Eyes()


def arm_mirror():
    """Makes the angle of beo's left arm match the angle of beo's right arm"""
    MOVEMENTS.disable_all_joints()
    while True:
        for i in range(3):
            angle = MOVEMENTS.get_raw_angle(i * 2)
            MOVEMENTS.set_raw_angle(i * 2 + 1, angle)
        sleep(0.01)


def eye_change():
    """Changes beo's eye expressions every few seconds"""
    expressions = ['wink', 'shut', 'sad', 'mad', 'default']
    while True:
        for i in expressions:
            EYES.set_expression(i)
            sleep(20)