Robotics StackExchange | Archived questions

execute ros functions inside a python file

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

how i can publish that.

Asked by iimata on 2022-08-07 17:23:53 UTC

Comments

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

Asked by ravijoshi on 2022-08-07 21:25:43 UTC

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")

Asked by iimata on 2022-08-08 09:25:19 UTC

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}}}"

Asked by iimata on 2022-08-08 09:27:41 UTC

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.

Asked by ravijoshi on 2022-08-08 21:32:35 UTC

Thanks alot Ravi <3

Asked by iimata on 2022-08-08 22:49:45 UTC

Answers