How to use length_buff method in Airtest

Best Python code snippet using Airtest

voice_cmd.py

Source:voice_cmd.py Github

copy

Full Screen

1#!/usr/bin/env python2# -*- coding:utf-8 -*-3import roslib; roslib.load_manifest('voice')4import os, sys5import playsound6import random7import rospy8import math9import copy10import re11from geometry_msgs.msg import Twist #运动速度结构体类型12from std_msgs.msg import String13# Python2.5 初始化后会删除 sys.setdefaultencoding,重新载入 14reload(sys)15sys.setdefaultencoding('utf-8')16class cmd_vel:17 def __init__(self):18 rospy.on_shutdown(self.cleanup)19 # 初始化默认速度20 self.speed_Linear = 0.221 self.speed_Angular = 0.522 self.msg = Twist()23 # self.tts="好的"24 # 震荡参数及msg缓存类堆栈,控制发布时间25 self.oscillation = {'oscil_Flag':0,'loop_Flag':0,'msg_Num':0,'keyWord':1,1:{'oscil_Num':0,'msg_Buff':Twist()}}26 self.oscillation_backup={}27 self.oscil_rate=1028 # 发布与订阅29 # turtlesim_mode30 # self.pub_ = rospy.Publisher('/turtle1/cmd_vel', Twist,queue_size=1)31 # turtlebot3_burger32 self.pub_ = rospy.Publisher('/cmd_vel', Twist,queue_size=1)33 # self.pubtts_ = rospy.Publisher('voice_feedback',String,queue_size=10)34 rospy.Subscriber('voice_txt', String, self.cmd_Extraction)35 # 预加载部分36 self.mp3_path=os.path.dirname(__file__)37 self.digit={"一":1,"二":2,"两":2,"三":3,"四":4,"五":5,"六":6,"七":7,"八":8,"九":9,"十":10}38 # 编译正则表达式39 # self.pattern1=re.compile(r'(?P<router>圆|正方形|长方形|矩形|前进|向前|加速|减速|左转|右转|后退|停止|立定|继续|恢复)')40 self.pattern1=re.compile(ur'(?P<router>\u5706|\u6B63\u65B9\u5F62|\u957F\u65B9\u5F62|\u77E9\u5F62|\u524D\u8FDB|\u5411\u524D|\u52A0\u901F|\u51CF\u901F|\u5DE6\u8F6C|\u53F3\u8F6C|\u540E\u9000|\u505C\u6B62|\u7ACB\u5B9A|\u7EE7\u7EED|\u6062\u590D)')41 # self.pattern2=re.compile(r'(?P<way>半径|直径|边长|前进|向前|后退)[^\d|一|二|两|三|四|五|六|七|八|九|十](?P<length>\d+|一|二|两|三|四|五|六|七|八|九|十).*(?P<direction>正|顺|逆)*.*(?P<router>圆|正方形)')42 self.pattern2=re.compile(ur'(?P<way>\u534A\u5F84|\u76F4\u5F84|\u8FB9\u957F|\u524D\u8FDB|\u5411\u524D|\u540E\u9000)\D*?(?P<length>\d+|\u4E00|\u4E8C|\u4E24|\u4E09|\u56DB|\u4E94|\u516D|\u4E03|\u516B|\u4E5D|\u5341)[^\u6B63|\u987A|\u9006]*(?P<direction>\u6B63(?:.[^\u5F62])|\u987A|\u9006)?')43 # 长-宽 类型长方形匹配44 self.pattern3=re.compile(ur'(?P<way_length>\u957F)\D*?(?P<length>\d+|\u4E00|\u4E8C|\u4E09|\u56DB|\u4E94|\u516D|\u4E03|\u516B|\u4E5D|\u5341|\u4E24).*(?P<way_wide>\u5BBD)\D*?(?P<wide>\d+|\u4E00|\u4E8C|\u4E09|\u56DB|\u4E94|\u516D|\u4E03|\u516B|\u4E5D|\u5341|\u4E24)[^\u6B63|\u987A|\u9006]*(?P<direction>\u6B63|\u987A|\u9006)?')45 # 宽-长 类型长方形匹配46 self.pattern4=re.compile(ur'(?P<way_wide>\u5BBD)\D*?(?P<wide>\d+|\u4E00|\u4E8C|\u4E09|\u56DB|\u4E94|\u516D|\u4E03|\u516B|\u4E5D|\u5341|\u4E24).*(?P<way_length>\u957F)\D*?(?P<length>\d+|\u4E00|\u4E8C|\u4E09|\u56DB|\u4E94|\u516D|\u4E03|\u516B|\u4E5D|\u5341|\u4E24)[^\u6B63|\u987A|\u9006]*(?P<direction>\u6B63|\u987A|\u9006)?')47 # 循环指令匹配pattern5=re.compile(r'(?P<notLoop>一个|走个)')48 self.pattern5=re.compile(ur'(?P<notLoop>\u8D70\u4E2A|\u4E00\u4E2A)')49 # 不同路径类型Twist发布频率控制50 rate = rospy.Rate(self.oscil_rate)51 while not rospy.is_shutdown():52 self.pub_.publish(self.msg)53 if self.oscillation['oscil_Flag']==1:54 key=self.oscillation['keyWord']55 self.msg=self.oscillation[key]['msg_Buff']56 self.oscillation[key]['oscil_Num']-=157 if self.oscillation[key]['oscil_Num']==0:58 self.oscillation['msg_Num']-=159 self.oscillation['keyWord']+=160 if self.oscillation['msg_Num']==0 and self.oscillation['loop_Flag']==1:61 self.oscillation=copy.deepcopy(self.oscillation_backup)62 elif self.oscillation['msg_Num']==0 and self.oscillation['loop_Flag']==0:63 self.oscillation['oscil_Flag']=264 # random_mp3=random.choice([1,2,3,4])65 # mp3_file=self.mp3_path+'/end'+str(random_mp3)+'.mp3'66 # playsound.playsound(mp3_file)67 elif self.oscillation['oscil_Flag']==2:68 self.msg=Twist()69 self.oscillation['oscil_Flag']=070 rate.sleep()71 #指令提取函数72 def cmd_Extraction(self, msg):73 rospy.loginfo(msg.data)74 #订阅数据字符串预处理75 command_Str=msg.data76 if '关闭' in command_Str:77 rospy.signal_shutdown("关闭机器人")78 # 尝试匹配运动路径控制关键词79 try:80 regex1=self.pattern1.search(command_Str.decode('utf-8'))81 router=regex1.group('router')82 except:83 # 非有效路径控制指令,退出回调函数84 # print('exit')85 return86 # print(router)87 # 圆形路径88 if router==u'\u5706':89 # print("flagtype=圆形")90 try:91 regex2=self.pattern2.search(command_Str.decode('utf-8'))92 way=regex2.group('way')93 length=regex2.group('length')94 # print(way)95 # print(length)96 except:97 return98 length=float(self.digit.get(length.encode('utf-8'),length))99 direction=self.direc(regex2)100 # print(direction)101 if way==u'\u534A\u5F84':102 radius=length103 elif way==u'\u76F4\u5F84':104 radius=length/2105 else:106 radius=0107 # print(radius)108 if radius:109 oscil_Buff=self.msg_Twist(2*radius*math.pi,1)110 self.oscillation[1]=oscil_Buff.copy()111 self.oscillation[1]['msg_Buff'].angular.z\112 =self.oscillation[1]['msg_Buff'].linear.x/radius*direction113 self.oscillation['msg_Num']=1114 self.notLoop(command_Str)115 116 # 正方形117 elif router==u'\u6B63\u65B9\u5F62':118 # print("flagtype=正方形")119 try:120 regex2=self.pattern2.search(command_Str.decode('utf-8'))121 way=regex2.group('way')122 length=regex2.group('length')123 # print(way)124 # print(length)125 except:126 return127 length=float(self.digit.get(length.encode('utf-8'),length))128 direction=self.direc(regex2)129 # print(direction)130 if way==u'\u8FB9\u957F':131 length_buff=self.msg_Twist(length,1)132 angular_buff=self.msg_Twist(0.5*math.pi,2,direction)133 self.oscillation['msg_Num']=8134 for i in range(1,9,2):135 self.oscillation[i]=length_buff.copy()136 self.oscillation[i+1]=angular_buff.copy()137 self.notLoop(command_Str)138 # 长方形 矩形139 elif router in (u'\u957F\u65B9\u5F62', u'\u77E9\u5F62'):140 # print("flagtype=长方形")141 try:142 regex3=self.pattern3.search(command_Str.decode('utf-8'))143 length=regex3.group('length')144 wide=regex3.group('wide')145 # print("长-宽")146 # print(length)147 # print(wide)148 except:149 try:150 regex3=self.pattern4.search(command_Str.decode('utf-8'))151 length=regex3.group('length')152 wide=regex3.group('wide')153 # print('宽-长')154 # print(length)155 # print(wide)156 except:157 return158 length=float(self.digit.get(length.encode('utf-8'),length))159 wide=float(self.digit.get(wide.encode('utf-8'),wide))160 direction=self.direc(regex3)161 if length and wide:162 length_buff=self.msg_Twist(length,1)163 wide_Buff=self.msg_Twist(wide,1)164 angular_buff=self.msg_Twist(0.5*math.pi,2,direction)165 self.oscillation['msg_Num']=8166 for i in range(1,9,4):167 self.oscillation[i]=length_buff.copy()168 self.oscillation[i+1]=angular_buff.copy()169 self.oscillation[i+2]=wide_Buff.copy()170 self.oscillation[i+3]=angular_buff.copy()171 self.notLoop(command_Str)172 # 前进 向前173 elif router in (u'\u524D\u8FDB',u'\u5411\u524D'):174 # print("flagtype=直线")175 try:176 regex4=self.pattern2.search(command_Str.decode('utf-8'))177 way=regex4.group('way')178 length=regex4.group('length')179 # print(way)180 # print(length)181 length=float(self.digit.get(length.encode('utf-8'),length))182 if way in (u'\u524D\u8FDB',u'\u5411\u524D'):183 length_buff=self.msg_Twist(length,1)184 self.oscillation[1]=length_buff.copy()185 self.oscillation['msg_Num']=1186 self.oscillation['oscil_Flag']=1187 except:188 # print("前进3")189 self.msg.linear.x = self.speed_Linear190 self.msg.angular.z = 0191 self.oscillation['oscil_Flag']=0192 # 加速193 elif router==u'\u52A0\u901F':194 # print("加速11")195 if self.oscillation['oscil_Flag']!=1 and\196 self.msg.linear.x>0 and self.msg.linear.x*2<=2.5:197 if self.msg.linear.z!=0:198 self.msg.linear.x = self.msg.linear.x*2199 self.msg.angular.z = self.msg.angular.z*2200 else:201 self.msg.linear.x +=0.2202 # 减速203 elif router==u'\u51CF\u901F':204 # print("减速2")205 if self.oscillation['oscil_Flag']!=1 and self.msg.linear.x-0.2>0:206 if self.msg.linear.z!=0:207 self.msg.linear.x = self.msg.linear.x/2208 self.msg.angular.z = self.msg.angular.z/2209 else:210 self.msg.linear.x -= 0.2211 # 左转212 elif router==u'\u5DE6\u8F6C':213 # print("左转4")214 if self.msg.linear.x != 0:215 if self.msg.angular.z < self.speed_Angular:216 self.msg.angular.z += 0.1217 if self.msg.angular.z > self.speed_Angular:218 self.msg.angular.z = self.speed_Angular219 self.oscillation['oscil_Flag']=0220 else:221 self.msg.angular.z = self.speed_Angular222 self.oscillation['oscil_Flag']=0223 # 右转224 elif router==u'\u53F3\u8F6C': 225 # print("右转5")226 if self.msg.linear.x != 0:227 if self.msg.angular.z > -self.speed_Angular:228 self.msg.angular.z -= 0.1229 if self.msg.angular.z < -self.speed_Angular:230 self.msg.angular.z = -self.speed_Angular231 self.oscillation['oscil_Flag']=0232 else:233 self.msg.angular.z = -self.speed_Angular234 self.oscillation['oscil_Flag']=0235 # 后退236 elif router==u'\u540E\u9000':237 # print("后退6")238 try:239 regex4=self.pattern2.search(command_Str.decode('utf-8'))240 way=regex4.group('way')241 length=regex4.group('length')242 # print(way)243 # print(length)244 length=float(self.digit.get(length.encode('utf-8'),length))245 if way==u'\u540E\u9000':246 length_buff=self.msg_Twist(length,1,-1)247 self.oscillation[1]=length_buff.copy()248 self.oscillation['msg_Num']=1249 self.oscillation['oscil_Flag']=1250 except:251 self.msg.linear.x = -self.speed_Linear252 self.msg.angular.z = 0253 self.oscillation['oscil_Flag']=0254 # 停止 立定255 elif router in (u'\u505C\u6B62',u'\u7ACB\u5B9A'):256 # print("停止7")257 self.oscillation['oscil_Flag']=2258 # 继续 恢复259 elif router in (u'\u7EE7\u7EED',u'\u6062\u590D'):260 # print("继续")261 self.oscillation['oscil_Flag']=1262 # self.pubtts_.publish(self.tts)263 random_mp3=random.choice([1,2])264 mp3_file=self.mp3_path+'/ok'+str(random_mp3)+'.mp3'265 playsound.playsound(mp3_file)266 # print(mp3_file)267 # os.system("play "+mp3_file)268 print("处理完成")269 # stop the robot!270 def cleanup(self):271 twist = Twist()272 self.pub_.publish(twist)273 # 尝试匹配路径轨迹方向274 def direc(self,regex):275 try:276 direction=regex.group('direction')[0:1]277 # print(direction)278 if direction in (u'\u6B63',u'\u987A'):279 return -1280 else:281 return 1282 except:283 return 1284 # Twist消息类型转换处理285 def msg_Twist(self,value,type,direction=1):286 self.oscillation = {'oscil_Flag':0,'msg_Num':0,'keyWord':1,'loop_Flag':0}287 temp={'oscil_Num':0,'msg_Buff':Twist()}288 if type==1:289 temp['oscil_Num']=(self.oscil_rate*value)//self.speed_Linear290 speed_temp=(self.oscil_rate*value)/temp['oscil_Num']291 temp['msg_Buff'].linear.x=speed_temp*direction292 elif type==2:293 temp['oscil_Num']=(self.oscil_rate* value)//self.speed_Angular294 speed_temp=(self.oscil_rate*value)/temp['oscil_Num']295 temp['msg_Buff'].angular.z=speed_temp*direction296 return temp297 # 循环指令匹配298 def notLoop(self,command_Str,flag=1):299 regex_notloop=self.pattern5.search(command_Str.decode('utf-8'))300 if regex_notloop:301 self.oscillation['loop_Flag']=0302 else:303 self.oscillation['loop_Flag']=1304 self.oscillation_backup=copy.deepcopy(self.oscillation)305 self.oscillation['oscil_Flag']=flag306 self.oscillation_backup['oscil_Flag']=flag307if __name__=="__main__":308 rospy.init_node('voice_cmd_node')309 try:310 cmd_vel()311 except rospy.ROSInterruptException:...

Full Screen

Full Screen

py3.py

Source:py3.py Github

copy

Full Screen

1#!/usr/bin/env python32# -*- coding:utf-8 -*-3import roslib; roslib.load_manifest('voice')4import os, sys5import rospy6import math7import copy8import re9from geometry_msgs.msg import Twist #运动速度结构体类型10from std_msgs.msg import String11# Python2.5 初始化后会删除 sys.setdefaultencoding,重新载入 12reload(sys)13sys.setdefaultencoding('utf-8')14class cmd_vel:15 def __init__(self):16 rospy.on_shutdown(self.cleanup)17 # 初始化默认速度18 self.speed_Linear = 119 self.speed_Angular = 0.520 self.msg = Twist()21 # self.tts="好的"22 # 震荡参数及msg缓存类堆栈,控制发布时间23 self.oscillation = {'oscil_Flag':0,'loop_Flag':0,'msg_Num':0,'keyWord':1,1:{'oscil_Num':0,'msg_Buff':Twist()}}24 self.oscillation_backup={}25 self.oscil_rate=1026 # 发布与订阅27 self.pub_ = rospy.Publisher('/turtle1/cmd_vel', Twist,queue_size=1)28 # self.pubtts_ = rospy.Publisher('voice_feedback',String,queue_size=10)29 rospy.Subscriber('voice_txt', String, self.cmd_Extraction)30 # 预加载部分31 self.digit={"一":1,"二":2,"两":2,"三":3,"四":4,"五":5,"六":6,"七":7,"八":8,"九":9,"十":10}32 # 编译正则表达式33 # self.pattern1=re.compile(r'(?P<router>圆|正方形|长方形|矩形|前进|向前|加速|减速|左转|右转|后退|停止|立定|继续|恢复)')34 self.pattern1=re.compile(r'(?P<router>\u5706|\u6B63\u65B9\u5F62|\u957F\u65B9\u5F62|\u77E9\u5F62|\u524D\u8FDB|\u5411\u524D|\u52A0\u901F|\u51CF\u901F|\u5DE6\u8F6C|\u53F3\u8F6C|\u540E\u9000|\u505C\u6B62|\u7ACB\u5B9A|\u7EE7\u7EED|\u6062\u590D)')35 # self.pattern2=re.compile(r'(?P<way>半径|直径|边长|前进|向前)[^\d|一|二|三|四|五|六|七|八|九|十](?P<length>\d+|一|二|三|四|五|六|七|八|九|十).*(?P<direction>正|顺|逆)*.*(?P<router>圆|正方形)')36 self.pattern2=re.compile(r'(?P<way>\u534A\u5F84|\u76F4\u5F84|\u8FB9\u957F|\u524D\u8FDB|\u5411\u524D)\D*(?P<length>\d+|\u4E00|\u4E8C|\u4E09|\u56DB|\u4E94|\u516D|\u4E03|\u516B|\u4E5D|\u5341)[^\u6B63|\u987A|\u9006]*(?P<direction>\u6B63(?:.[^\u5F62])|\u987A|\u9006)?')37 # 长-宽 类型长方形匹配38 self.pattern3=re.compile(r'(?P<way_length>\u957F)\D*(?P<length>\d+|\u4E00|\u4E8C|\u4E09|\u56DB|\u4E94|\u516D|\u4E03|\u516B|\u4E5D|\u5341).*(?P<way_wide>\u5BBD)\D*(?P<wide>\d+|\u4E00|\u4E8C|\u4E09|\u56DB|\u4E94|\u516D|\u4E03|\u516B|\u4E5D|\u5341)[^\u6B63|\u987A|\u9006]*(?P<direction>\u6B63|\u987A|\u9006)?')39 # 宽-长 类型长方形匹配40 self.pattern4=re.compile(r'(?P<way_wide>\u5BBD)\D*(?P<wide>\d+|\u4E00|\u4E8C|\u4E09|\u56DB|\u4E94|\u516D|\u4E03|\u516B|\u4E5D|\u5341).*(?P<way_length>\u957F)\D*(?P<length>\d+|\u4E00|\u4E8C|\u4E09|\u56DB|\u4E94|\u516D|\u4E03|\u516B|\u4E5D|\u5341)[^\u6B63|\u987A|\u9006]*(?P<direction>\u6B63|\u987A|\u9006)?')41 # 循环指令匹配pattern5=re.compile(r'(?P<notLoop>一个|走个)')42 self.pattern5=re.compile(r'(?P<notLoop>\u8D70\u4E2A|\u4E00\u4E2A)')43 # 不同路径类型Twist发布频率控制44 rate = rospy.Rate(self.oscil_rate)45 while not rospy.is_shutdown():46 self.pub_.publish(self.msg)47 if self.oscillation['oscil_Flag']==1:48 key=self.oscillation['keyWord']49 self.msg=self.oscillation[key]['msg_Buff']50 self.oscillation[key]['oscil_Num']-=151 if self.oscillation[key]['oscil_Num']==0:52 self.oscillation['msg_Num']-=153 self.oscillation['keyWord']+=154 if self.oscillation['msg_Num']==0 and self.oscillation['loop_Flag']==1:55 self.oscillation=copy.deepcopy(self.oscillation_backup)56 elif self.oscillation['msg_Num']==0 and self.oscillation['loop_Flag']==0:57 self.oscillation['oscil_Flag']=258 elif self.oscillation['oscil_Flag']==2:59 self.msg=Twist()60 self.oscillation['oscil_Flag']=061 rate.sleep()62 #指令提取函数63 def cmd_Extraction(self, msg):64 rospy.loginfo(msg.data)65 #订阅数据字符串预处理66 commond_Str=msg.data67 # 尝试匹配运动路径控制关键词68 try:69 regex1=self.pattern1.search(commond_Str.decode('utf-8'))70 router=regex1.group('router')71 except:72 # 非有效路径控制指令,退出回调函数73 return74 print(router)75 # 圆形路径76 if router==u'\u5706':77 print("flagtype=圆形")78 try:79 regex2=self.pattern2.search(commond_Str.decode('utf-8'))80 way=regex2.group('way')81 length=regex2.group('length')82 print(way)83 print(length)84 except:85 return86 length=float(self.digit.get(length.encode('utf-8'),length))87 direction=self.direc(regex2)88 print(direction)89 if way==u'\u534A\u5F84':90 radius=length91 elif way==u'\u76F4\u5F84':92 radius=length/293 else:94 radius=095 print(radius)96 if radius:97 oscil_Buff=self.msg_Twist(2*radius*math.pi,1)98 self.oscillation[1]=oscil_Buff.copy()99 self.oscillation[1]['msg_Buff'].angular.z\100 =self.oscillation[1]['msg_Buff'].linear.x/radius*direction101 self.oscillation['msg_Num']=1102 self.notLoop(commond_Str)103 104 # 正方形105 elif router==u'\u6B63\u65B9\u5F62':106 print("flagtype=正方形")107 try:108 regex2=self.pattern2.search(commond_Str.decode('utf-8'))109 way=regex2.group('way')110 length=regex2.group('length')111 print(way)112 print(length)113 except:114 return115 length=float(self.digit.get(length.encode('utf-8'),length))116 direction=self.direc(regex2)117 print(direction)118 if way==u'\u8FB9\u957F':119 length_buff=self.msg_Twist(length,1)120 angular_buff=self.msg_Twist(0.5*math.pi,2,direction)121 self.oscillation['msg_Num']=8122 for i in range(1,9,2):123 self.oscillation[i]=length_buff.copy()124 self.oscillation[i+1]=angular_buff.copy()125 self.notLoop(commond_Str)126 # 长方形 矩形127 elif router in (u'\u957F\u65B9\u5F62', u'\u77E9\u5F62'):128 print("flagtype=长方形")129 try:130 regex3=self.pattern3.search(commond_Str.decode('utf-8'))131 length=regex3.group('length')132 wide=regex3.group('wide')133 print(length)134 print(wide)135 except:136 try:137 regex3=self.pattern4.search(commond_Str.decode('utf-8'))138 length=regex3.group('length')139 wide=regex3.group('wide')140 print(length)141 print(wide)142 except:143 return144 length=float(self.digit.get(length.encode('utf-8'),length))145 wide=float(self.digit.get(wide.encode('utf-8'),wide))146 direction=self.direc(regex3)147 if length and wide:148 length_buff=self.msg_Twist(length,1)149 wide_Buff=self.msg_Twist(wide,1)150 angular_buff=self.msg_Twist(0.5*math.pi,2,direction)151 self.oscillation['msg_Num']=8152 for i in range(1,9,4):153 self.oscillation[i]=length_buff.copy()154 self.oscillation[i+1]=angular_buff.copy()155 self.oscillation[i+2]=wide_Buff.copy()156 self.oscillation[i+3]=angular_buff.copy()157 self.notLoop(commond_Str)158 # 前进 向前159 elif router in (u'\u524D\u8FDB',u'\u5411\u524D'):160 print("flagtype=直线")161 try:162 regex4=self.pattern2.search(commond_Str.decode('utf-8'))163 way=regex4.group('way')164 length=regex4.group('length')165 print(way)166 print(length)167 length=float(self.digit.get(length.encode('utf-8'),length))168 if way in (u'\u524D\u8FDB',u'\u5411\u524D'):169 length_buff=self.msg_Twist(length,1)170 self.oscillation[1]=length_buff.copy()171 self.oscillation['msg_Num']=1172 self.oscillation['oscil_Flag']=1173 except:174 print("前进3")175 self.msg.linear.x = self.speed_Linear176 self.msg.angular.z = 0177 self.oscillation['oscil_Flag']=0178 # 加速179 elif router==u'\u52A0\u901F':180 print("加速11")181 if self.oscillation['oscil_Flag']!=1 and\182 self.msg.linear.x>0 and self.msg.linear.x*2<=2.5:183 if self.msg.linear.z!=0:184 self.msg.linear.x = self.msg.linear.x*2185 self.msg.angular.z = self.msg.angular.z*2186 else:187 self.msg.linear.x +=0.2188 # 减速189 elif router==u'\u51CF\u901F':190 print("减速2")191 if self.oscillation['oscil_Flag']!=1 and self.msg.linear.x-0.2>0:192 if self.msg.linear.z!=0:193 self.msg.linear.x = self.msg.linear.x/2194 self.msg.angular.z = self.msg.angular.z/2195 else:196 self.msg.linear.x -= 0.2197 # 左转198 elif router==u'\u5DE6\u8F6C':199 print("左转4")200 if self.msg.linear.x != 0:201 if self.msg.angular.z < self.msg.linear.x:202 self.msg.angular.z += 0.1203 self.oscillation['oscil_Flag']=0204 else:205 self.msg.angular.z = self.speed_Angular206 self.oscillation['oscil_Flag']=0207 # 右转208 elif router==u'\u53F3\u8F6C': 209 print("右转5")210 if self.msg.linear.x != 0:211 if self.msg.angular.z > 0:212 self.msg.angular.z = -0.1213 self.oscillation['oscil_Flag']=0214 elif self.msg.angular.z>-self.msg.linear.x and self.msg.angular.z < 0:215 self.msg.angular.z-=0.1216 self.oscillation['oscil_Flag']=0217 else:218 self.msg.angular.z = -self.speed_Angular219 self.oscillation['oscil_Flag']=0220 # 后退221 elif router==u'\u540E\u9000':222 print("后退6")223 self.msg.linear.x = -self.speed_Linear224 self.msg.angular.z = 0225 self.oscillation['oscil_Flag']=0226 # 停止 立定227 elif router in (u'\u505C\u6B62',u'\u7ACB\u5B9A'):228 print("停止7")229 self.oscillation['oscil_Flag']=2230 # 继续 恢复231 elif router in (u'\u7EE7\u7EED',u'\u6062\u590D'):232 print("继续")233 self.oscillation['oscil_Flag']=1234 # self.pubtts_.publish(self.tts)235 print("处理完成")236 # stop the robot!237 def cleanup(self):238 twist = Twist()239 self.pub_.publish(twist)240 # 尝试匹配路径轨迹方向241 def direc(self,regex):242 try:243 direction=regex.group('direction')[0:1]244 print(direction)245 if direction in (u'\u6B63',u'\u987A'):246 return -1247 else:248 return 1249 except:250 return 1251 # Twist消息类型转换处理252 def msg_Twist(self,value,type,direction=1):253 self.oscillation = {'oscil_Flag':0,'msg_Num':0,'keyWord':1,'loop_Flag':0}254 temp={'oscil_Num':0,'msg_Buff':Twist()}255 if type==1:256 temp['oscil_Num']=(self.oscil_rate*value)//self.speed_Linear257 speed_temp=(self.oscil_rate*value)/temp['oscil_Num']258 temp['msg_Buff'].linear.x=speed_temp259 elif type==2:260 temp['oscil_Num']=(self.oscil_rate* value)//self.speed_Angular261 speed_temp=(self.oscil_rate*value)/temp['oscil_Num']262 temp['msg_Buff'].angular.z=speed_temp*direction263 return temp264 # 循环指令匹配265 def notLoop(self,commond_Str,flag=1):266 regex_notloop=self.pattern5.search(commond_Str.decode('utf-8'))267 if regex_notloop:268 self.oscillation['loop_Flag']=0269 else:270 self.oscillation['loop_Flag']=1271 self.oscillation_backup=copy.deepcopy(self.oscillation)272 self.oscillation['oscil_Flag']=flag273 self.oscillation_backup['oscil_Flag']=flag274if __name__=="__main__":275 rospy.init_node('voice_cmd_node')276 try:277 cmd_vel()278 except rospy.ROSInterruptException:...

Full Screen

Full Screen

client.py

Source:client.py Github

copy

Full Screen

1import socket2import struct3host = "127.0.0.1"4port = 90015# 创建一个客户端的socket对象6client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)7# 连接服务端8client.connect((host, port))9sendmsg = "hello"10info_length = len(sendmsg)11total_length = 4 + info_length + 212length_buff = struct.pack("!I", total_length)13buff = length_buff + "{}\r\n".format(sendmsg).encode("utf-8")14client.send(buff)15msg = client.recv(1024)16print(msg.decode("utf-8"))...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Airtest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful