![](/img/trans.png)
[英]How to gracefully stop a Dockerized Python ROS2 node when run with docker-compose up?
[英]ROS2 python node location
I want to create a python ros2 node that reads some data from a csv file and then use it, this csv file is put in the dirctory:workspace/src/<pkg_name>/<pkg_name> beside the ros2 python node
當我從這個目錄運行這個節點時它工作正常,但是當我使用colcon build構建 pkg 並使用ros2 run <pkg_name> <node_name>運行這個節點時它會產生錯誤 no such file or directory
解決方案是在我打開 csv 時放置完整路徑
但是我在這里的問題是如何不能使用完整路徑並仍然使其工作,當我使用colcon 構建工作時,我的節點在哪里被復制,或者我可以使用哪些 ros2 特定的內部變量
#with open("/home/ali/Engineering/ITI/low_speed_self_driving_vehicles/ROS_lectures/GWS/src/iti_lab_9/iti_lab_9/turtle_commands.csv",'r', newline='') as csvfile:
with open("turtle_commands.csv",'r', newline='') as csvfile:
csvread = csv.reader(csvfile, delimiter=',')
next(csvread)
for row in csvread:
self.linear_x.append(float(row[0]))
self.angular_z.append(float(row[1]))
self.index=0
因為當您啟動 package 時,啟動路徑很可能不在 csv 旁邊。
您可以將其添加到您的腳本中
import os
def path_script():
_path = os.path.dirname(os.path.abspath(__file__))
_path = _path.replace('\\', '/')
return _path
path_script()
檢查。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.