execute ros functions inside a python file

asked 2022-08-07 17:23:53 -0500

iimata gravatar image

im trying to pub a nav2_goal under a pyhon file inside if statement

how i can publish that.

edit retag flag offensive close merge delete

Comments

2

I strongly recommend mentioning your code to understand the problem better.

ravijoshi gravatar image ravijoshi  ( 2022-08-07 21:25:43 -0500 )edit

i have this code when the camera detect a person i need to publish a nav2_goal

 for *xyxy, conf, cls in reversed(det):
                if save_txt:  # Write to file
                    xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist()  # normalized xywh
                    line = (cls, *xywh, conf) if save_conf else (cls, *xywh)  # label format
                    with open(f'{txt_path}.txt', 'a') as f:
                        f.write(('%g ' * len(line)).rstrip() % line + '\n')

                if save_img or save_crop or view_img:  # Add bbox to image
                    c = int(cls)  # integer class
                    label = None if hide_labels else (names[c] if hide_conf else f'{names[c]} {conf:.2f}')
                    annotator.box_label(xyxy, label, color=colors(c, True))
                if names[c] == 'person':
                    print("hiii")
iimata gravatar image iimata  ( 2022-08-08 09:25:19 -0500 )edit

this is my goal that i need to publish

ros2 topic pub /goal_pose geometry_msgs/PoseStamped "{header: {stamp: {sec: 0}, frame_id: 'map'}, pose: {position: {x: 5.0, y: -2.0, z: 0.0}, orientation: {w: 1.0}}}"

iimata gravatar image iimata  ( 2022-08-08 09:27:41 -0500 )edit

Two things. 1) Please format your code properly and then move it from comment section to question. 2) "i need to publish", please look at the ROS tutorial page titled "Writing a Simple Publisher and Subscriber (Python)". It is beautifully written with complete explanation.

ravijoshi gravatar image ravijoshi  ( 2022-08-08 21:32:35 -0500 )edit

Thanks alot Ravi <3

iimata gravatar image iimata  ( 2022-08-08 22:49:45 -0500 )edit