Skip to content

Commit

Permalink
Merge pull request #270 from gsalinas/can-namespace-pr
Browse files Browse the repository at this point in the history
Put components loaded by the device container into its namespace, if any.
  • Loading branch information
ipa-vsp authored Apr 22, 2024
2 parents 893079d + b3dfdc9 commit 93127ee
Show file tree
Hide file tree
Showing 7 changed files with 1,854 additions and 0 deletions.
8 changes: 8 additions & 0 deletions canopen_core/src/device_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ bool DeviceContainer::load_component(
opts.use_global_arguments(false);
opts.use_intra_process_comms(true);
std::vector<std::string> remap_rules;

std::string can_ns = this->get_namespace();
if (!can_ns.empty())
{
remap_rules.push_back("--ros-args");
remap_rules.push_back("-r");
remap_rules.push_back("__ns:=" + can_ns);
}
remap_rules.push_back("--ros-args");
// remap_rules.push_back("--log-level");
// remap_rules.push_back("debug");
Expand Down
1 change: 1 addition & 0 deletions canopen_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ find_package(lely_core_libraries REQUIRED)
generate_dcf(simple)
generate_dcf(canopen_system)
cogen_dcf(cia402_system)
cogen_dcf(cia402_namespaced_system)
cogen_dcf(cia402)
generate_dcf(cia402_lifecycle)
cogen_dcf(cia402_diagnostics)
Expand Down
11 changes: 11 additions & 0 deletions canopen_tests/ROS_NAMESPACES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
The `cia402_namespaced_system.launch.py` example demonstrates how to run a
CIA402 system in a namespace to allow multiple CANOpen-based robots in the
same ROS domain. This example is necessary because the controller names
are picked up from `ros2_controllers.yaml` and we must define their names
in that file with a `__namespace__/controller_name:` key, then use
ReplaceString from `nav2_common` to dynamically add the namespace to the
controller definition.

For a proxy system, no example is included; it's sufficient to include, e.g.
the `proxy_setup.launch.py` launch description in another launch file and
push a namespace onto it with PushROSNamespace in the ordinary way.
56 changes: 56 additions & 0 deletions canopen_tests/config/cia402_namespaced_system/bus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
options:
dcf_path: "@BUS_CONFIG_PATH@"

master:
node_id: 1
driver: "ros2_canopen::MasterDriver"
package: "canopen_master_driver"
sync_period: 10000

defaults:
dcf: "cia402_slave.eds"
driver: "ros2_canopen::Cia402Driver"
package: "canopen_402_driver"
period: 10
revision_number: 0
sdo:
- {index: 0x60C2, sub_index: 1, value: 50} # Set interpolation time for cyclic modes to 50 ms
- {index: 0x60C2, sub_index: 2, value: -3} # Set base 10-3s
- {index: 0x6081, sub_index: 0, value: 1000}
- {index: 0x6083, sub_index: 0, value: 2000}
tpdo: # TPDO needed statusword, actual velocity, actual position, mode of operation
1:
enabled: true
cob_id: "auto"
transmission: 0x01
mapping:
- {index: 0x6041, sub_index: 0} # status word
- {index: 0x6061, sub_index: 0} # mode of operation display
2:
enabled: true
cob_id: "auto"
transmission: 0x01
mapping:
- {index: 0x6064, sub_index: 0} # position actual value
- {index: 0x606c, sub_index: 0} # velocity actual position
3:
enabled: false
4:
enabled: false
rpdo: # RPDO needed controlword, target position, target velocity, mode of operation
1:
enabled: true
cob_id: "auto"
mapping:
- {index: 0x6040, sub_index: 0} # controlword
- {index: 0x6060, sub_index: 0} # mode of operation
2:
enabled: true
cob_id: "auto"
mapping:
- {index: 0x607A, sub_index: 0} # target position
- {index: 0x60FF, sub_index: 0} # target velocity

nodes:
cia402_device_1:
node_id: 2
Loading

0 comments on commit 93127ee

Please sign in to comment.