roscppクライアントを使用してrospyサーバを呼び出そうとしています。残念ながら、私のサーバーが問題なく正しく動作しているように見えても、クライアントからの私の呼び出しは常に失敗します。私はクライアントとサーバーのコードを私が受け取った出力(私は要求に応じてCMakeList.txtとpackage.xmlを含めることができますが、以下のファイルのどこかに問題があると確信しています)と一緒に含めました。roscppクライアントがrospyサービスを呼び出すことができません
service.py:
#!/usr/bin/env python
from std_srvs.srv import Empty, EmptyResponse
import rospy
def serviceCall(call):
print "service called"
return EmptyResponse()
def serviceCall_server():
rospy.init_node('service_server')
s = rospy.Service('a_new_service', Empty, serviceCall)
print "Ready to receive service calls."
rospy.spin()
if __name__ == "__main__":
serviceCall_server()
client.cpp:
#include <ros/ros.h>
#include <std_srvs/Empty.h>
int main(int argc, char** argv){
ros::init(argc, argv, "service_client");
ros::NodeHandle n;
ros::Rate r(30);
ros::ServiceClient service_call = n.serviceClient<std_srvs::Empty>("/a_new_service", 100);
std_srvs::Empty srv;
service_call.waitForExistence();
if (service_call.call(srv))
{
ROS_ERROR("Successfully called service a_new_service");
}
else
{
ROS_ERROR("Failed to call service a_new_service");
}
}
起動ファイル:起動ファイルから
<launch>
<node name="server" pkg="test" type="server.py" output="screen"/>
<node name="client" pkg="test" type="client" output="screen" />
</launch>
出力:
core service [/rosout] found
process[server-1]: started with pid [25659]
process[client-2]: started with pid [25660]
[ INFO] [1485448779.402439557]: waitForService: Service [/a_new_service] has not been advertised, waiting...
Ready to receive service calls.
[ INFO] [1485448779.630636002]: waitForService: Service [/a_new_service] is now available.
[ERROR] [1485448779.630685730]: Failed to call service a_new_service
起動ファイルを実行すると、サービス呼び出しが失敗します(出力の最後の行を参照)。私は電話でrosservice call/a_new_service {}を端末から正常に呼び出すことができます。これは私のクライアントに何か間違っていると信じさせるが、何が間違っているのかは分かりません。
-
EDIT:だから、さらに調査すると、これは私がrosrunを使用して、サーバーとクライアントの両方を呼び出し、それらが正常に通信持つことができていますので、起動ファイルに障害のようです。なぜ起動ファイルが呼び出しにエラーを引き起こすのか誰にも分かりますか?特に、waitForService呼び出しによってサーバーが使用可能であることを考慮してください。