요구사항
때때로 여러 개의 마스터가 필요하고 주제 콘텐츠를 교환해야 하는 경우가 있습니다. 이때 ros와 함께 제공되는 동일한 마스터를 설정하는 방법을 사용할 수 없습니다.
우리의 처리 방법은 서로 다른 마스터에서 실행되는 클라이언트와 서버를 구성하는 것입니다. 클라이언트는 master1 아래의 topic1을 구독한 다음 이를 tcp 프로토콜을 통해 master2 아래의 서버로 보냅니다(자체적으로 메시지 프로토콜 형식을 정의). . 메시지를 구문 분석한 후 master2 아래에 topic1을 게시하여 ros의 주제 프레임워크를 변경하지 않고도 master1에서 master2로 topic1 메시지를 전파할 수 있습니다.
아래에서 구현하는 것은 amcl_pose 주제를 변환하는 것입니다. 메시지 유형은 master1에서 master2로 전송되는 PoseWithCovarianceStamped이고 다른 주제 코드는
클라이언트 코드
#! /usr/bin/env python# -*- coding=utf-8 -*-import socketimport structimport rospyimport timefrom geometry_msgs.msg import PoseWithCovarianceStamped,PoseStamped#message proto# id | length | datadef send_msg(sock, msg ,id): # Prefix each message with a 4-byte id and length (network byte order) msg = struct.pack('>I',int(id)) + struct.pack('>I', len(msg)) + msg sock.sendall(msg)def odomCallback(msg): global odom_socket data = "" id = msg.header.seq print "send id: ",id x = msg.pose.pose.position.x y = msg.pose.pose.position.y #orientation orien_z = msg.pose.pose.orientation.z orien_w = msg.pose.pose.orientation.w data += str(x) + "," + str(y)+ "," + str(orien_z)+ "," + str(orien_w) send_msg(odom_socket,data,id) odom_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) odom_socket.connect(('127.0.0.1',8000)) rospy.init_node('server_node') rospy.Subscriber('/amcl_pose',PoseWithCovarianceStamped,odomCallback) rospy.spin()
서버 코드
#! /usr/bin/env python# -*- coding=utf-8 -*-import socketimport time,os,fcntlimport structimport rospyfrom geometry_msgs.msg import PoseWithCovarianceStamped,PoseStamped#message proto# id | length | datadef recv_msg(sock): try: # Read message length and unpack it into an integer raw_id = recvall(sock, 4) if not raw_id: return None id = struct.unpack('>I', raw_id)[0] print "receive id: ",id raw_msglen = recvall(sock, 4) if not raw_msglen: return None msglen = struct.unpack('>I', raw_msglen)[0] # Read the message data return recvall(sock, msglen) except Exception ,e: return Nonedef recvall(sock, n): # Helper function to recv n bytes or return None if EOF is hit data = '' while len(data) < n: packet = sock.recv(n - len(data)) if not packet: return None data += packet return data##把接受的数据重新打包成ros topic发出去def msg_construct(data): list = data.split(',') pose = PoseWithCovarianceStamped() pose.header.stamp = rospy.Time.now() pose.header.frame_id = "/map" pose.pose.pose.position.x = float(list[0]) pose.pose.pose.position.y = float(list[1]) pose.pose.pose.position.z = 0 pose.pose.pose.orientation.x = 0 pose.pose.pose.orientation.y = 0 pose.pose.pose.orientation.z = float(list[2]) pose.pose.pose.orientation.w = float(list[3]) pose.pose.covariance = [0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.06853891945200942] return pose#初始化socket,监听8000端口odom_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) odom_socket.bind(('',8000)) odom_socket.listen(10) (client,address) = odom_socket.accept() rospy.init_node("client_node") odom_pub = rospy.Publisher("/amcl_pose",PoseWithCovarianceStamped,queue_size=30) r = rospy.Rate(1000)#设置noblock,否则会阻塞在接听,下面while不会一直循环,只有在有数据才进行下一次循环fcntl.fcntl(client, fcntl.F_SETFL, os.O_NONBLOCK)while not rospy.is_shutdown(): data = recv_msg(client) if data: odom_pub.publish(msg_construct(data)) r.sleep()
결론
위 코드는 LAN에서 테스트되었으며 이미지 및 레이저 데이터를 전송할 때 데이터가 손실되지 않는지 확인할 수 있습니다.
Arraysinpython, 특히 비밀 복구를위한 ArecrucialInscientificcomputing.1) theaRearedFornumericalOperations, DataAnalysis 및 MachinELearning.2) Numpy'SimplementationIncensuressuressurations thanpythonlists.3) arraysenablequick

Pyenv, Venv 및 Anaconda를 사용하여 다양한 Python 버전을 관리 할 수 있습니다. 1) PYENV를 사용하여 여러 Python 버전을 관리합니다. Pyenv를 설치하고 글로벌 및 로컬 버전을 설정하십시오. 2) VENV를 사용하여 프로젝트 종속성을 분리하기 위해 가상 환경을 만듭니다. 3) Anaconda를 사용하여 데이터 과학 프로젝트에서 Python 버전을 관리하십시오. 4) 시스템 수준의 작업을 위해 시스템 파이썬을 유지하십시오. 이러한 도구와 전략을 통해 다양한 버전의 Python을 효과적으로 관리하여 프로젝트의 원활한 실행을 보장 할 수 있습니다.

Numpyarrayshaveseveraladvantagesstandardpythonarrays : 1) thearemuchfasterduetoc 기반 간증, 2) thearemorememory-refficient, 특히 withlargedatasets 및 3) wepferoptizedformationsformationstaticaloperations, 만들기, 만들기

어레이의 균질성이 성능에 미치는 영향은 이중입니다. 1) 균질성은 컴파일러가 메모리 액세스를 최적화하고 성능을 향상시킬 수 있습니다. 2) 그러나 유형 다양성을 제한하여 비 효율성으로 이어질 수 있습니다. 요컨대, 올바른 데이터 구조를 선택하는 것이 중요합니다.

tocraftexecutablepythonscripts, 다음과 같은 비스트 프랙티스를 따르십시오 : 1) 1) addashebangline (#!/usr/bin/envpython3) tomakethescriptexecutable.2) setpermissionswithchmod xyour_script.py.3) organtionewithlarstringanduseifname == "__"

numpyarraysarebetterfornumericaloperations 및 multi-dimensionaldata, mumemer-efficientArrays

numpyarraysarebetterforheavynumericalcomputing, whilearraymoduleisiMoresuily-sportainedprojectswithsimpledatatypes.1) numpyarraysofferversatively 및 formanceforgedatasets 및 complexoperations.2) Thearraymoduleisweighit 및 ep

ctypesallowscreatingandmanipulatingC-stylearraysinPython.1)UsectypestointerfacewithClibrariesforperformance.2)CreateC-stylearraysfornumericalcomputations.3)PassarraystoCfunctionsforefficientoperations.However,becautiousofmemorymanagement,performanceo


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

mPDF
mPDF는 UTF-8로 인코딩된 HTML에서 PDF 파일을 생성할 수 있는 PHP 라이브러리입니다. 원저자인 Ian Back은 자신의 웹 사이트에서 "즉시" PDF 파일을 출력하고 다양한 언어를 처리하기 위해 mPDF를 작성했습니다. HTML2FPDF와 같은 원본 스크립트보다 유니코드 글꼴을 사용할 때 속도가 느리고 더 큰 파일을 생성하지만 CSS 스타일 등을 지원하고 많은 개선 사항이 있습니다. RTL(아랍어, 히브리어), CJK(중국어, 일본어, 한국어)를 포함한 거의 모든 언어를 지원합니다. 중첩된 블록 수준 요소(예: P, DIV)를 지원합니다.

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.
