yanshee 机器人2

import YanAPI
from time import sleep
#初始化
ip_addr = "192.168.137.148" # please change to your yanshee robot IP
YanAPI.yan_api_init(ip_addr)
#数据定义区
dong=[{"RightAnkleUD":100,"LeftAnkleUD":100},
      {'RightAnkleFB': 110, 'RightAnkleUD': 105, 'RightHipFB': 14, 'RightHipLR': 60, 'RightKneeFlex': 33},
      {'LeftAnkleFB': 35, 'LeftAnkleUD': 113, 'LeftHipFB': 145, 'LeftHipLR': 81, 'LeftKneeFlex': 165, 'RightAnkleFB': 0, 'RightAnkleUD': 90, 'RightHipFB': 30, 'RightHipLR': 23, 'RightKneeFlex': 94,'RightElbowFlex': 126, 'RightShoulderFlex': 57, 'RightShoulderRoll': 90},
      {'LeftAnkleFB': 65, 'LeftAnkleUD': 104, 'LeftHipFB': 127, 'LeftHipLR': 82, 'LeftKneeFlex': 121, 'RightAnkleFB': 0, 'RightAnkleUD': 112, 'RightHipFB': 17, 'RightHipLR': 60, 'RightKneeFlex': 158},
      {'LeftAnkleFB': 34, 'LeftAnkleUD': 105, 'LeftHipFB': 149, 'LeftHipLR': 97, 'LeftKneeFlex': 177, 'RightAnkleFB': 100, 'RightAnkleUD': 112, 'RightHipFB': 25, 'RightHipLR': 90, 'RightKneeFlex': 150},
      {'LeftAnkleFB': 16, 'LeftAnkleUD': 100, 'LeftHipFB': 110, 'LeftHipLR': 87, 'LeftKneeFlex': 153, 'RightAnkleFB': 100, 'RightAnkleUD': 85, 'RightHipFB': 55, 'RightHipLR': 82, 'RightKneeFlex': 145},
      {'LeftAnkleFB': 17, 'LeftAnkleUD': 89, 'LeftHipFB': 53, 'LeftHipLR': 88, 'LeftKneeFlex': 86, 'RightAnkleFB': 41, 'RightAnkleUD': 95, 'RightHipFB': 32, 'RightHipLR': 85, 'RightKneeFlex': 118},
      {'LeftAnkleFB': 90, 'LeftAnkleUD': 70, 'LeftHipFB': 78, 'LeftHipLR': 80, 'LeftKneeFlex': 69, 'RightAnkleFB': 82, 'RightAnkleUD': 88, 'RightHipFB': 17, 'RightHipLR': 80, 'RightKneeFlex': 76, 'RightElbowFlex': 165, 'RightShoulderFlex': 140, 'RightShoulderRoll': 90},
      {'LeftAnkleFB': 90, 'LeftAnkleUD': 70, 'LeftHipFB': 60, 'LeftHipLR': 80, 'LeftKneeFlex': 70, 'RightAnkleFB': 100, 'RightAnkleUD': 75, 'RightHipFB': 30, 'RightHipLR': 88, 'RightKneeFlex': 80},
      {'LeftAnkleFB': 90, 'LeftAnkleUD': 77, 'LeftHipFB': 45, 'LeftHipLR': 93, 'LeftKneeFlex': 69, 'RightAnkleFB': 100, 'RightAnkleUD': 75, 'RightHipFB': 30, 'RightHipLR': 88, 'RightKneeFlex': 75},
      {'LeftAnkleFB': 177, 'LeftAnkleUD': 88, 'LeftHipFB': 156, 'LeftHipLR': 168, 'LeftKneeFlex': 109, 'RightAnkleFB': 97, 'RightAnkleUD': 68, 'RightHipFB': 40, 'RightHipLR': 94, 'RightKneeFlex': 73, 'LeftElbowFlex': 64, 'LeftShoulderFlex': 146, 'LeftShoulderRoll': 90},
      {'LeftAnkleFB': 98, 'LeftAnkleUD': 70, 'LeftHipFB': 134, 'LeftHipLR': 103, 'LeftKneeFlex': 84,'RightAnkleFB': 110, 'RightAnkleUD': 72, 'RightHipFB': 60, 'RightHipLR': 95, 'RightKneeFlex': 76,'LeftElbowFlex': 38, 'LeftShoulderFlex': 35, 'LeftShoulderRoll': 84},
      {'LeftAnkleFB': 71,'LeftAnkleUD': 90,'LeftElbowFlex': 15,'LeftHipFB': 120,'LeftHipLR': 90,'LeftKneeFlex': 104,'LeftShoulderFlex': 40,'LeftShoulderRoll': 90,'RightAnkleFB': 110,'RightAnkleUD': 90,'RightElbowFlex': 165,'RightHipFB': 60,'RightHipLR': 90,'RightKneeFlex': 75,'RightShoulderFlex': 140,'RightShoulderRoll': 90}]
kua=[{'LeftAnkleFB': 70, 'LeftAnkleUD': 90, 'LeftElbowFlex': 15, 'LeftHipFB': 120, 'LeftHipLR': 90, 'LeftKneeFlex': 104, 'LeftShoulderFlex': 40, 'LeftShoulderRoll': 90, 'NeckLR': 90, 'RightAnkleFB': 110, 'RightAnkleUD': 90, 'RightElbowFlex': 165, 'RightHipFB': 60, 'RightHipLR': 90, 'RightKneeFlex': 76, 'RightShoulderFlex': 140, 'RightShoulderRoll': 90},
        {'LeftAnkleFB': 31, 'LeftAnkleUD': 106, 'LeftElbowFlex': 75, 'LeftHipFB': 155, 'LeftHipLR': 88, 'LeftKneeFlex': 180, 'LeftShoulderFlex': 94, 'LeftShoulderRoll': 90, 'NeckLR': 90, 'RightAnkleFB': 147, 'RightAnkleUD': 100, 'RightElbowFlex': 67, 'RightHipFB': 32, 'RightHipLR': 92, 'RightKneeFlex': 5, 'RightShoulderFlex': 112, 'RightShoulderRoll': 90},
        {'LeftAnkleFB': 31, 'LeftAnkleUD': 109, 'LeftElbowFlex': 75, 'LeftHipFB': 155, 'LeftHipLR': 86, 'LeftKneeFlex': 180, 'LeftShoulderFlex': 94, 'LeftShoulderRoll': 90, 'NeckLR': 90, 'RightAnkleFB': 146, 'RightAnkleUD': 99, 'RightElbowFlex': 67, 'RightHipFB': 32, 'RightHipLR': 28, 'RightKneeFlex': 5, 'RightShoulderFlex': 112, 'RightShoulderRoll': 90},
        {'LeftAnkleFB': 30, 'LeftAnkleUD': 110, 'LeftElbowFlex': 75, 'LeftHipFB': 155, 'LeftHipLR': 86, 'LeftKneeFlex': 180, 'LeftShoulderFlex': 94, 'LeftShoulderRoll': 90, 'NeckLR': 90, 'RightAnkleFB': 75, 'RightAnkleUD': 99, 'RightElbowFlex': 67, 'RightHipFB': 25, 'RightHipLR': 26, 'RightKneeFlex': 157, 'RightShoulderFlex': 112, 'RightShoulderRoll': 90},
        {'LeftAnkleFB': 29, 'LeftAnkleUD': 110, 'LeftElbowFlex': 75, 'LeftHipFB': 155, 'LeftHipLR': 85, 'LeftKneeFlex': 180, 'LeftShoulderFlex': 94, 'LeftShoulderRoll': 90, 'NeckLR': 90, 'RightAnkleFB': 105, 'RightAnkleUD': 99, 'RightElbowFlex': 67, 'RightHipFB': 26, 'RightHipLR': 85, 'RightKneeFlex': 152, 'RightShoulderFlex': 112, 'RightShoulderRoll': 90},
        {'LeftAnkleFB': 13, 'LeftAnkleUD': 104, 'LeftElbowFlex': 75, 'LeftHipFB': 124, 'LeftHipLR': 77, 'LeftKneeFlex': 156, 'LeftShoulderFlex': 94, 'LeftShoulderRoll': 90, 'NeckLR': 90, 'RightAnkleFB': 72, 'RightAnkleUD': 99, 'RightElbowFlex': 67, 'RightHipFB': 33, 'RightHipLR': 85, 'RightKneeFlex': 156, 'RightShoulderFlex': 112, 'RightShoulderRoll': 90},
        {'LeftAnkleFB': 18, 'LeftAnkleUD': 87, 'LeftElbowFlex': 75, 'LeftHipFB': 62, 'LeftHipLR': 82, 'LeftKneeFlex': 73, 'LeftShoulderFlex': 94, 'LeftShoulderRoll': 90, 'NeckLR': 90, 'RightAnkleFB': 8, 'RightAnkleUD': 82, 'RightElbowFlex': 67, 'RightHipFB': 13, 'RightHipLR': 85, 'RightKneeFlex': 157, 'RightShoulderFlex': 112, 'RightShoulderRoll': 90},
        {'LeftAnkleFB': 12, 'LeftAnkleUD': 87, 'LeftElbowFlex': 75, 'LeftHipFB': 83, 'LeftHipLR': 82, 'LeftKneeFlex': 73, 'LeftShoulderFlex': 94, 'LeftShoulderRoll': 90, 'NeckLR': 90, 'RightAnkleFB': 23, 'RightAnkleUD': 67, 'RightElbowFlex': 67, 'RightHipFB': 9, 'RightHipLR': 85, 'RightKneeFlex': 175, 'RightShoulderFlex': 112, 'RightShoulderRoll': 90},
        {'LeftAnkleFB': 18, 'LeftAnkleUD': 87, 'LeftElbowFlex': 75, 'LeftHipFB': 72, 'LeftHipLR': 169, 'LeftKneeFlex': 72, 'LeftShoulderFlex': 94, 'LeftShoulderRoll': 90, 'NeckLR': 90, 'RightAnkleFB': 25, 'RightAnkleUD': 68, 'RightElbowFlex': 67, 'RightHipFB': 9, 'RightHipLR': 90, 'RightKneeFlex': 175, 'RightShoulderFlex': 112, 'RightShoulderRoll': 90},
        {'LeftAnkleFB': 59, 'LeftAnkleUD': 60, 'LeftElbowFlex': 75, 'LeftHipFB': 169, 'LeftHipLR': 180, 'LeftKneeFlex': 47, 'LeftShoulderFlex': 94, 'LeftShoulderRoll': 90, 'NeckLR': 90, 'RightAnkleFB': 24, 'RightAnkleUD': 66, 'RightElbowFlex': 67, 'RightHipFB': 9, 'RightHipLR': 91, 'RightKneeFlex': 175, 'RightShoulderFlex': 112, 'RightShoulderRoll': 90},
        {'LeftAnkleFB': 57, 'LeftAnkleUD': 68, 'LeftElbowFlex': 75, 'LeftHipFB': 160, 'LeftHipLR': 147, 'LeftKneeFlex': 78, 'LeftShoulderFlex': 94, 'LeftShoulderRoll': 90, 'NeckLR': 90, 'RightAnkleFB': 28, 'RightAnkleUD': 88, 'RightElbowFlex': 67, 'RightHipFB': 43, 'RightHipLR': 96, 'RightKneeFlex': 176, 'RightShoulderFlex': 112, 'RightShoulderRoll': 90},
        {'LeftAnkleFB': 105, 'LeftAnkleUD': 76, 'LeftElbowFlex': 75, 'LeftHipFB': 160, 'LeftHipLR': 109, 'LeftKneeFlex': 79, 'LeftShoulderFlex': 94, 'LeftShoulderRoll': 90, 'NeckLR': 90, 'RightAnkleFB': 45, 'RightAnkleUD': 87, 'RightElbowFlex': 67, 'RightHipFB': 59, 'RightHipLR': 94, 'RightKneeFlex': 168, 'RightShoulderFlex': 112, 'RightShoulderRoll': 90},
        {'LeftAnkleFB': 70, 'LeftAnkleUD': 89, 'LeftElbowFlex': 15, 'LeftHipFB': 120, 'LeftHipLR': 90, 'LeftKneeFlex': 104, 'LeftShoulderFlex': 40, 'LeftShoulderRoll': 90, 'NeckLR': 90, 'RightAnkleFB': 110, 'RightAnkleUD': 90, 'RightElbowFlex': 165, 'RightHipFB': 60, 'RightHipLR': 90, 'RightKneeFlex': 76, 'RightShoulderFlex': 140, 'RightShoulderRoll': 90}]
you=[
    {'LeftAnkleFB': 66, 'LeftAnkleUD': 82, 'LeftHipFB': 113, 'LeftHipLR': 93, 'LeftKneeFlex': 102,'RightAnkleFB': 110, 'RightAnkleUD': 79, 'RightHipFB': 60, 'RightHipLR': 95, 'RightKneeFlex': 75},
    {'LeftAnkleFB': 84, 'LeftAnkleUD': 84, 'LeftHipFB': 132, 'LeftHipLR': 90, 'LeftKneeFlex': 101,'RightAnkleFB': 110, 'RightAnkleUD': 80, 'RightHipFB': 60, 'RightHipLR': 95, 'RightKneeFlex': 75},
    {'LeftAnkleFB': 66, 'LeftAnkleUD': 82, 'LeftHipFB': 113, 'LeftHipLR': 93, 'LeftKneeFlex': 102,'RightAnkleFB': 110, 'RightAnkleUD': 80, 'RightHipFB': 60, 'RightHipLR': 95, 'RightKneeFlex': 75}
]
zuo=[
    {'LeftAnkleFB': 70, 'LeftAnkleUD': 95, 'LeftElbowFlex': 15, 'LeftHipFB': 120, 'LeftHipLR': 86, 'LeftKneeFlex': 105, 'LeftShoulderFlex': 40, 'LeftShoulderRoll': 90, 'NeckLR': 90, 'RightAnkleFB': 110, 'RightAnkleUD': 90, 'RightElbowFlex': 165, 'RightHipFB': 60, 'RightHipLR': 89, 'RightKneeFlex': 75, 'RightShoulderFlex': 140, 'RightShoulderRoll': 90},
    {'LeftAnkleFB': 70, 'LeftAnkleUD': 95, 'LeftElbowFlex': 15, 'LeftHipFB': 120, 'LeftHipLR': 86, 'LeftKneeFlex': 105, 'LeftShoulderFlex': 40, 'LeftShoulderRoll': 90, 'NeckLR': 90, 'RightAnkleFB': 97, 'RightAnkleUD': 90, 'RightElbowFlex': 165, 'RightHipFB': 48, 'RightHipLR': 87, 'RightKneeFlex': 76, 'RightShoulderFlex': 140, 'RightShoulderRoll': 90},
    {'LeftAnkleFB': 70, 'LeftAnkleUD': 92, 'LeftElbowFlex': 15, 'LeftHipFB': 120, 'LeftHipLR': 86, 'LeftKneeFlex': 104, 'LeftShoulderFlex': 40, 'LeftShoulderRoll': 90, 'NeckLR': 90, 'RightAnkleFB': 120, 'RightAnkleUD': 92, 'RightElbowFlex': 165, 'RightHipFB': 67, 'RightHipLR': 87, 'RightKneeFlex': 73, 'RightShoulderFlex': 140, 'RightShoulderRoll': 90}
  ]
jioValue1 = [
    {'LeftAnkleFB': 40, 'LeftAnkleUD': 110, 'LeftHipFB': 130, 'LeftHipLR': 70, 'LeftKneeFlex': 152, 'RightAnkleFB': 165, 'RightAnkleUD': 117, 'RightHipFB': 49, 'RightHipLR': 62, 'RightKneeFlex': 2},
    {'LeftAnkleFB': 40, 'LeftAnkleUD': 112, 'LeftHipFB': 130, 'LeftHipLR': 68, 'LeftKneeFlex': 154, 'RightAnkleFB': 95, 'RightAnkleUD': 115, 'RightHipFB': 16, 'RightHipLR': 64, 'RightKneeFlex': 38},
    {'LeftAnkleFB': 25, 'LeftAnkleUD': 70, 'LeftHipFB': 96, 'LeftHipLR': 108, 'LeftKneeFlex': 128, 'RightAnkleFB': 127, 'RightAnkleUD': 72, 'RightHipFB': 42, 'RightHipLR': 105, 'RightKneeFlex': 37}
]
jioValue2 = [
    {'LeftAnkleFB': 15, 'LeftAnkleUD': 63, 'LeftHipFB': 131, 'LeftHipLR': 118, 'LeftKneeFlex': 178, 'RightAnkleFB': 140, 'RightAnkleUD': 69, 'RightHipFB': 50, 'RightHipLR': 110, 'RightKneeFlex': 29},
    {'LeftAnkleFB': 85, 'LeftAnkleUD': 65, 'LeftHipFB': 163, 'LeftHipLR': 116, 'LeftKneeFlex': 142, 'RightAnkleFB': 140, 'RightAnkleUD': 68, 'RightHipFB': 50, 'RightHipLR': 111, 'RightKneeFlex': 27},
    {'LeftAnkleFB': 53, 'LeftAnkleUD': 108, 'LeftHipFB': 137, 'LeftHipLR': 74, 'LeftKneeFlex': 143, 'RightAnkleFB': 155, 'RightAnkleUD': 110, 'RightHipFB': 84, 'RightHipLR': 72, 'RightKneeFlex': 52}
]
def run(flag): 
    while 1:
        now=YanAPI.get_sensors_gyro()['data']['gyro'][0]['euler-z']
        err=now-flag
        if abs(err)>180:
            err=-err
        if abs(err)<5:
            break
        elif err<0:
            play(zuo,500)
        elif err>0:
            play(you,500)
def walk(x,flag):
    run(flag)
    oldx = x
    YanAPI.set_servos_angles({'LeftAnkleFB': 40, 'LeftAnkleUD': 111, 'LeftHipFB': 130, 'LeftHipLR': 72, 'LeftKneeFlex': 150, 'RightAnkleFB': 139, 'RightAnkleUD': 110, 'RightHipFB': 45, 'RightHipLR': 72, 'RightKneeFlex': 27},1000)
    sleep(1)
    if x%2:
        x-=1
    count = int(x/2)
    while count:
        for i in range(len(jioValue1)):
            YanAPI.set_servos_angles(jioValue1[i],1000)
            sleep(1)
        for i in range(len(jioValue2)):
            YanAPI.set_servos_angles(jioValue2[i],1000)
            sleep(1)
        count-=1
    if oldx%2:
        for i in range(len(jioValue1)):
            YanAPI.set_servos_angles(jioValue1[i],1000)
            sleep(1)
        YanAPI.set_servos_angles(jioValue2[0],1000)
    else:
        YanAPI.set_servos_angles(jioValue1[0],1000)
    sleep(1)
    YanAPI.set_servos_angles({'LeftAnkleFB': 70, 'LeftAnkleUD': 90, 'LeftHipFB': 120, 'LeftHipLR': 90, 'LeftKneeFlex': 105, 'RightAnkleFB': 110, 'RightAnkleUD': 90, 'RightHipFB': 60, 'RightHipLR': 90, 'RightKneeFlex': 74},1000)
    sleep(1)


def play(dong,speed):
    for i in range(len(dong)):
        YanAPI.set_servos_angles(dong[i],speed)
        sleep(1)



def avold(bu,dire,flag):
    for i in range(bu):
        run(flag)
        YanAPI.sync_play_motion(name="walk",direction=dire,repeat=1)
        
def color():
    res = YanAPI.sync_do_color_recognition()
    color_dict = {"no color detected":"没有检测到颜色","pink":"粉","red":"红","green":"绿","blue":"蓝","yellow":"黄","cyan":"青","magenta":"洋红","orange":"橙","violet":"紫","brown":"棕","black":"黑","white":"白","gray":"灰"}
    result = res["data"]["color"][0]["name"]
    for key in color_dict:
        if(key == result):
            color_res = color_dict[key]
            return(color_res+"色")



# flag=YanAPI.get_sensors_gyro()['data']['gyro'][0]['euler-z']
# YanAPI.start_voice_tts("开始人脸识别",False)  
# YanAPI.start_play_music('pai.mp3')
# res=YanAPI.sync_do_face_recognition_value('recognition')    
# YanAPI.start_voice_tts("这个人是"+res,False)   
# YanAPI.start_voice_tts("以完成人脸识别是否前进",False)
# while 1:
#     if YanAPI.sync_do_voice_asr_value()['question']=="开始":
#         break
# YanAPI.sync_play_motion(name="walk",direction='forward',repeat=3)
# res=YanAPI.get_sensors_infrared_value()
# run(flag)
# if res<500:
#     YanAPI.start_voice_tts("检测到障碍物距离"+str(res),False)
#     avold(6,'left',flag)
#     avold(6,'forward',flag-10)
#     avold(9,'right',flag)
# else:
#     YanAPI.start_voice_tts("未检测到障碍物",False)
#     avold(6,'forward',flag-10)

# run(150)
# YanAPI.sync_play_motion()
# sleep(2)
play(kua,1000)
# avold(3,'forward',flag-30)
# YanAPI.set_servos_angles(kua[0],1000)
# flag=YanAPI.get_sensors_gyro()['data']['gyro'][0]['euler-z']
# # YanAPI.sync_play_motion('举手')
# walk(3,flag)
# res=YanAPI.get_sensors_infrared_value()
# if res<500:
#     YanAPI.start_voice_tts("检测到障碍物距离"+str(res),False)
#     avold(8,'left',flag)
#     YanAPI.sync_play_motion()
#     sleep(1)
#     walk(6,flag)
#     sleep(1)
#     avold(12,'right',flag)
#     YanAPI.sync_play_motion()
#     sleep(1)
#     walk(1,flag)
# else:
#     YanAPI.start_voice_tts("未检测到障碍物",False)
#     walk(6,flag)


# sleep(1)
# YanAPI.sync_play_motion('跨界')
# walk(3,flag)
# ***********第二部分**********#

# flag=YanAPI.get_sensors_gyro()['data']['gyro'][0]['euler-z']
# flag= flag if flag>0 else flag+360
# YanAPI.sync_play_motion('拍照')
# YanAPI.start_play_music('pai.mp3')
# res=color()
# YanAPI.sync_play_motion()
# YanAPI.start_voice_tts("检测到"+res+"物体请问放到几号区域", False)
# sleep(3)
# YanAPI.sync_play_motion()
# while 1:
#     hao=YanAPI.sync_do_voice_asr_value()['question']
#     if hao=='3号'or hao=='2号'or hao=='1号':
#         break
# YanAPI.start_voice_tts("收到指令,物品箱编号为"+hao,False)
# YanAPI.sync_play_motion('报箱子')

# avold(20,'right',247)
# run(154)
# play(bu,1000)
# walk(3)
# YanAPI.sync_play_motion()
# run(130)
# avold(3,'right',150)

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值