简体   繁体   中英

How to set ROS_PACKAGE_PATH environment variable before starting debug environment in VSCode?

I would like to add /home/sanya/work/ORB_SLAM3/Examples/ROS to the ROS_PACKAGE_PATH variable before the ROS debug session starts. If it isn't added, the debugger won't start, because it cannot find the package. A would like to export the variable before the ROS debug starts. What I already tried:

  • I tried to add it as an environment variable in the launch.json 2 ways:

first way, launch.json:

{
        "name": "ROS: Launch + build (release)",
        "type": "ros",
        "request": "launch",
        "target": "/home/sanya/work/ORB_SLAM3/Examples/ROS/ORB_SLAM3/launch/ORB_SLAM3_bag.launch",
        "env": {"ROS_PACKAGE_PATH": "/opt/ros/melodic/share:/home/sanya/work/ORB_SLAM3/Examples/ROS"}
}

second way, launch.json:

{
        "name": "ROS: Launch + build (release)",
        "type": "ros",
        "request": "launch",
        "target": "/home/sanya/work/ORB_SLAM3/Examples/ROS/ORB_SLAM3/launch/ORB_SLAM3_bag.launch",
        "environment": [{"name": "ROS_PACKAGE_PATH", "value": "/opt/ros/melodic/share:/home/sanya/work/ORB_SLAM3/Examples/ROS"}]
}
  • I tried to add it to an.env file, and set the envFile property in launch.json

.env:

ROS_PACKAGE_PATH=/opt/ros/melodic/share:/home/sanya/work/ORB_SLAM3/Examples/ROS

launch.json:

{
        "name": "ROS: Launch + build (release)",
        "type": "ros",
        "request": "launch",
        "target": "/home/sanya/work/ORB_SLAM3/Examples/ROS/ORB_SLAM3/launch/ORB_SLAM3_bag.launch",
        "envFile": "${workspaceFolder}/.env"
}
  • I tried to run export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/home/sanya/work/ORB_SLAM3_multi/Examples/ROS as a prelaunchTask this works, the export happens (I echoed ROS_PACKAGE_PATH after it), but the debug session starts in a different terminal (if I understand correctly) and the the variable won't be set to the correct value in the debug session.

The only thing that works for me, is adding it to the.bashrc file. This isn't really ok for me, because I have a modified version of the same library, and I would like to use them both (I will benchmark the modified version against the original), and I wouldn't like to modify the.bshrc file everytime when switching between the 2 versions.

(I maintain the Microsoft VSCode ROS extension.) The extension inherits most of the environment from the ROS environment it is launched from, so if you need to set environment variables (or relocate ROS), you can set them in a terminal and launch code from the terminal.

I create a feature request - https://github.com/ms-iot/vscode-ros/issues/646 , and assigned it to our 0.8.0 which I'm working on now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM