ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

[python] output of a code be called in another python code automatically

asked 2022-08-17 04:25:12 -0600

Delbina gravatar image

Hi everyone,

I have a robot equipped with different sensors. one of them is 3d lidar. i have used the pointcloud and converted them into lasersacn. now i have written a simple python code which do object detction and specify the distance from the nearest object to the lidar based on the lasersan ranges. this is the first code, now i have written another code which should use this value and start moving and stop when it reach near the object. now my problem is that i want the distance value specified in the first code(output of the first code, for instance it would say 10 m to the object), automatically be called in the second code. what should i do?

thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-08-17 04:43:34 -0600

ravijoshi gravatar image

There are many choices/design decisions to take at this point.

  1. The simplest idea is to publish the distance value as a latched topic. Then, in your second program, please make a subscriber, listening to the published topic. This way, you can easily get the distance value in your second program.
  2. Another approach could be making use of ROS Service. On the first program (node), please make a service server that returns the distance from the object. Then, please create a service client on the second program (node) to get the distance value.

Once you have the distance value, you can execute the move command.

edit flag offensive delete link more

Comments

thanks a lot

Delbina gravatar image Delbina  ( 2022-08-17 04:51:38 -0600 )edit

@Ravi Joshi i want to use the first suggestion, I have defined publisher in the first code and subscriber in the second code. now just running the first code and then the second code would be ok?

Delbina gravatar image Delbina  ( 2022-08-17 05:02:55 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2022-08-17 04:25:12 -0600

Seen: 113 times

Last updated: Aug 17 '22