|
| 1 | +# ROS2 Package {{ros.package_name}} |
| 2 | + |
| 3 | + |
| 4 | +## Installation and Setup |
| 5 | + |
| 6 | +Move or link the auto-generated ROS2 package (folder `{{ros.package_name}}`) to your workspace source tree (typically `~/ros2_ws/src/`). |
| 7 | + |
| 8 | +Compile with: |
| 9 | + |
| 10 | +```console |
| 11 | +cd ~/ros2_ws/ |
| 12 | +colcon build --packages-select {{ros.package_name}} |
| 13 | +source install/setup.bash |
| 14 | +``` |
| 15 | + |
| 16 | +If you build the package in-place from its own directory instead of a larger |
| 17 | +workspace, source the generated setup script from `install/`: |
| 18 | + |
| 19 | +```console |
| 20 | +# bash |
| 21 | +source install/setup.bash |
| 22 | + |
| 23 | +# zsh |
| 24 | +source install/setup.zsh |
| 25 | +``` |
| 26 | + |
| 27 | +On macOS, ROS2 logging may need an explicit writable directory: |
| 28 | + |
| 29 | +```console |
| 30 | +mkdir -p .ros_log |
| 31 | +export ROS_LOG_DIR="$PWD/.ros_log" |
| 32 | +``` |
| 33 | + |
| 34 | + |
| 35 | +## Launch and Use |
| 36 | + |
| 37 | +Start the optimizer in one terminal. The process stays in the foreground while |
| 38 | +the node is running. |
| 39 | + |
| 40 | +```console |
| 41 | +# terminal 1 |
| 42 | +source install/setup.bash # or: source install/setup.zsh |
| 43 | +ros2 run {{ros.package_name}} {{ros.node_name}} |
| 44 | +``` |
| 45 | + |
| 46 | +In a second terminal, source the same environment and verify discovery: |
| 47 | + |
| 48 | +```console |
| 49 | +# terminal 2 |
| 50 | +source install/setup.bash # or: source install/setup.zsh |
| 51 | +ros2 node list --no-daemon --spin-time 5 |
| 52 | +ros2 topic list --no-daemon --spin-time 5 |
| 53 | +``` |
| 54 | + |
| 55 | +You should see the node `/{{ros.node_name}}`, the input topic |
| 56 | +`/{{ros.subscriber_subtopic}}`, and the output topic |
| 57 | +`/{{ros.publisher_subtopic}}`. |
| 58 | + |
| 59 | +Then publish a request to the configured parameters topic |
| 60 | +(default: `/{{ros.subscriber_subtopic}}`): |
| 61 | + |
| 62 | +```console |
| 63 | +ros2 topic pub --once /{{ros.subscriber_subtopic}} {{ros.package_name}}/msg/OptimizationParameters "{parameter: [YOUR_PARAMETER_VECTOR], initial_guess: [INITIAL_GUESS_OPTIONAL], initial_y: [], initial_penalty: 15.0}" |
| 64 | +``` |
| 65 | + |
| 66 | +The result will be announced on the configured result topic |
| 67 | +(default: `/{{ros.publisher_subtopic}}`): |
| 68 | + |
| 69 | +```console |
| 70 | +ros2 topic echo /{{ros.publisher_subtopic}} |
| 71 | +``` |
| 72 | + |
| 73 | +To get the optimal solution you can do: |
| 74 | + |
| 75 | +```console |
| 76 | +ros2 topic echo /{{ros.publisher_subtopic}} --field solution |
| 77 | +``` |
| 78 | + |
| 79 | + |
| 80 | +## Messages |
| 81 | + |
| 82 | +This package involves two messages: `OptimizationParameters` |
| 83 | +and `OptimizationResult`, which are used to define the input |
| 84 | +and output values to the node. `OptimizationParameters` specifies |
| 85 | +the parameter vector, the initial guess (optional), the initial |
| 86 | +guess for the vector of Lagrange multipliers and the initial value |
| 87 | +of the penalty value. `OptimizationResult` is a message containing |
| 88 | +all information related to the solution of the optimization |
| 89 | +problem, including the optimal solution, the solver status, |
| 90 | +solution time, Lagrange multiplier vector and more. |
| 91 | + |
| 92 | +The message structures are defined in the following msg files: |
| 93 | + |
| 94 | +- [`OptimizationParameters.msg`](msg/OptimizationParameters.msg) |
| 95 | +- [`OptimizationResult.msg`](msg/OptimizationResult.msg) |
| 96 | + |
| 97 | + |
| 98 | +## Configure |
| 99 | + |
| 100 | +You can configure the rate and topic names by editing |
| 101 | +[`config/open_params.yaml`](config/open_params.yaml). |
| 102 | + |
| 103 | + |
| 104 | +## Directory structure and contents |
| 105 | + |
| 106 | +The following auto-generated files are included in your ROS2 package: |
| 107 | + |
| 108 | +```txt |
| 109 | +├── CMakeLists.txt |
| 110 | +├── config |
| 111 | +│ └── open_params.yaml |
| 112 | +├── extern_lib |
| 113 | +│ └── librosenbrock.a |
| 114 | +├── include |
| 115 | +│ ├── open_optimizer.hpp |
| 116 | +│ └── rosenbrock_bindings.hpp |
| 117 | +├── launch |
| 118 | +│ └── open_optimizer.launch.py |
| 119 | +├── msg |
| 120 | +│ ├── OptimizationParameters.msg |
| 121 | +│ └── OptimizationResult.msg |
| 122 | +├── package.xml |
| 123 | +├── README.md |
| 124 | +└── src |
| 125 | + └── open_optimizer.cpp |
| 126 | +``` |
0 commit comments