修改声呐参数,以将声呐量程修改为10m为例,其余参数修改可参照协议文件。
1、client_test.py
python3 clien_test.py 13 10
python
elif cmd == str(13):
print("set sonar range: " + str(value))
arrBuff = b'\xee\xbb\xee\x03'
arrBuff += struct.pack('i', int(value))
arrBuff += b'\xee\xaa\xee\xff'
在协议文件中,修改声呐量程的协议为:
故模块将该数据包发送至auv_server。
2、auv_server.py
python
# cmd callback state msg
if pkg_head == b'\xee\xff\xee\xff':
print(self.cmd_callback_state[recv_msg[4:8]])
直接将指令转发至center_server
3、center_sever.py
python
# send the control_center cmd from auv to the control_center module on nx
def recv_control_center_msg(self):
#self.sonar_param_socket, self.sonar_param_addr = self.sonar_param_server.accept()
while True:
cmd_msg = self.nx_client.recv(1024)
if len(cmd_msg) > 3:
# send the control_center cmd to the control_center module
if cmd_msg[-4:] == b'\xee\xff\xee\xff':
self.control_center_socket.send(cmd_msg)
# send the sonar parameters cmd to the sonar module
elif cmd_msg[-4:] == b'\xee\xaa\xee\xff':
self.sonar_param_socket.send(cmd_msg)
else:
print("cmd from auv error, no such cmd...")
根据'\ee\aa\ee\ff'判断为带参数的指令,转sonar_node
4、sonar_node(此处以ros1版本中的驱动代码举例)
python
# receive tcp cmd msg from center server, set the sonar parameter
def recv_tcp_cmd(self):
...
# set the sonar_range, 1~120
elif sonar_msg[0:4] == b'\xee\xbb\xee\x03':
sonar_range = struct.unpack('i', sonar_msg[4:8])[0]
sonar_range_cmd = 'rosrun dynamic_reconfigure dynparam set sonar_imager range_m ' + str(sonar_range)
sonar_subprocess = subprocess.Popen(sonar_range_cmd, shell=True, executable="/bin/bash")
完成设置
数据包通过网口传输至声呐,声呐解码后进行参数调整。