I can't find any issue or example for communication between ROS1 outside docker and apollo modules. I mean:
inside docker I launch bootstrap
outside from docker I start rostopic pub -r 10 /test/tf1 geometry_msgs/TransformStamped '{header:{}, child_frame_id: "", transform: {}}'
inside docker I have code in apollo/modules/localization/my_localization/my_localization.cc
void MY_tf_Callback(const geometry_msgs::TransformStamped& msg)
{
AINFO << "I heard TransformStamped" ;
}
ros::Subscriber sub;
ros::Publisher pub;
Status MyLocalization::Start() {
std::shared_ptr<ros::NodeHandle> nh = AdapterManager::node_handle();
// std::shared_ptr<ros::NodeHandle> nh = std::make_shared<ros::NodeHandle>();
sub = nh->subscribe("/test/tf1", 32, MY_tf_Callback);
pub = nh->advertise<geometry_msgs::TransformStamped>("/test/tf2", 1000);
}
void CARLALocalization::OnTimer(const ros::TimerEvent &event) {
geometry_msgs::TransformStamped msg;
pub.publish(msg);
}
Expected behavior:
inside docker I'll have topics /test/tf1 and /test/tf2.
outside docker I'll have topics /test/tf1 and /test/tf2.
In file /apollo/data/log/localization.INFO I'll see "I heard TransformStamped"
inside docker rostopic echo -c /test/tf1 will print some messages.
outside docker rostopic echo -c /test/tf2 will print some messages.
Real behaviour:
inside docker I'll have only topic /test/tf1.
outside docker I'll have only topic /test/tf1.
In file /apollo/data/log/localization.INFO I don't see "I heard TransformStamped"
inside docker rostopic echo -c /test/tf1 print
/use_sim_time is not set, will not subscribe to simulated time [/clock] topic
add those lines to dev_start.sh
--env ROS_MASTER_URI=http://172.17.0.1:11311 \
--env ROS_IP=172.17.0.1 \
then you can connect to apollo's rosmaster outside docker
Update. Second try.
I has one simulation environment that can also provide /tf and /clock topics.
I modified my code :
sub = nh->subscribe("/tf", 32, MY_tf_Callback);
And right now i have:
inside docker I'll have topics /tf /clock.
outside docker I'll have topics /tf /clock.
In file /apollo/data/log/localization.INFO I don't see "I heard TransformStamped"
inside docker rostopic echo -c /tf print
transforms:
header:
seq: 0
stamp:
secs: 0
nsecs: 0
frame_id: world
child_frame_id: localization
transform:
translation:
x: 0.0
y: 0.0
z: 0.0
rotation:
x: 0.0
y: 0.0
z: 0.0w: 0.0
4.1outside docker
transforms:
header:
seq: 0
stamp:
secs: 974
nsecs: 447999999
frame_id: "map"
child_frame_id: "base_link"
transform:
translation:
x: 314.974945068
y: -330.60748291
z: 38.1035308838
rotation:
x: 8.41813594205e-10
y: 3.45706910466e-06
z: -0.000243504987536
w: 0.999999970347
@yonhdee Thanks for advice!
I think you mean add
-e ROS_MASTER_URI=http://172.17.0.1:11311 \
-e ROS_IP=172.17.0.1 \
into docker run command.
If Im right. Here are results:
P.S. I'll do more separated test and will provide results as soon as I can.
First of all I think some troubles can exists in getting and using ros::NodeHandle.
I got it by custom method .
in /apollo/modules/common/adapters/adapter_manager.h I add
class AdapterManager {
...
std::shared_ptr<ros::NodeHandle> node_handle__;
static std::shared_ptr<ros::NodeHandle> node_handle() {return instance()->node_handle__;};
...
}
in /apollo/modules/common/adapters/adapter_manager.cc I add
void AdapterManager::Init(const AdapterManagerConfig &configs) {
...
if (configs.is_ros()) {
instance()->node_handle__.reset(new ros::NodeHandle());
instance()->node_handle_.reset(instance()->node_handle__.get());
}
...
}
I make new ros::NodeHandle inside my localization module by this:
std::shared_ptr<ros::NodeHandle> nh;
nh = std::make_shared<ros::NodeHandle>();
But nothing changes.
I think I have notice that I use apollo 2.5. I start my project then 3.0 does not exist. And I has not read out any important for my projects notes from 'Release notes'. Have I install and start use v.3.0?
My example will show resolving this issue with new localization module. You can change any other or write your own new module.
apollo/modules/localization/my_localization/my_localization.h
class MyLocalization
{
ros::Subscriber sub;
ros::Publisher pub;
std::shared_ptr
}
apollo/modules/localization/my_localization/my_localization.cc
void MY_tf_Callback(const tf2_msgs::TFMessage & msg)
{
AINFO << "I heard TransformStamped" ;
}
Status MyLocalization::Start()
{
nh = std::make_shared
sub = nh->subscribe("/test/tf1", 32, MY_tf_Callback);
pub = nh->advertise
}
void MyLocalization::OnTimer(const ros::TimerEvent &event)
{
geometry_msgs::TransformStamped msg;
pub.publish(msg);
}
P.S. I think point 3 is a bug but I'm not sure that I make everything the best way.
P.P.S. I didn't try organize communication between several apollo modules that contains regular ros subscribers and publishers and also I didn't try use regular ros services inside apollo modules. I think it can be useful experience.
Thanks everyone for attention and help!
@gladijos
Thank you so much!!! This helped us big time! thank you for making this guide!
@mickeyouyou @quning78
This should be one of the Apollo guides in docs
closing the issue.
@snuffysasa Thanks, welcome if you do want ,you can pull a request for that.
Most helpful comment
My example will show resolving this issue with new localization module. You can change any other or write your own new module.
apollo/modules/localization/my_localization/my_localization.h nh;
class MyLocalization
{
ros::Subscriber sub;
ros::Publisher pub;
std::shared_ptr
}
apollo/modules/localization/my_localization/my_localization.cc
void MY_tf_Callback(const tf2_msgs::TFMessage & msg)
{
AINFO << "I heard TransformStamped" ;
}
Status MyLocalization::Start()();("/test/tf2", 1000);
{
nh = std::make_shared
sub = nh->subscribe("/test/tf1", 32, MY_tf_Callback);
pub = nh->advertise
}
void MyLocalization::OnTimer(const ros::TimerEvent &event)
{
geometry_msgs::TransformStamped msg;
pub.publish(msg);
}
P.S. I think point 3 is a bug but I'm not sure that I make everything the best way.
P.P.S. I didn't try organize communication between several apollo modules that contains regular ros subscribers and publishers and also I didn't try use regular ros services inside apollo modules. I think it can be useful experience.
Thanks everyone for attention and help!