-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Phase out launchCanBus in favor of yarprobotinterface #271
Comments
Parameters can be passed to each device like follows: config.xml: <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE robot PUBLIC "-//YARP//DTD yarprobotinterface 3.0//EN" "http://www.yarp.it/DTD/yarprobotinterfaceV3.0.dtd">
<robot name="teo" build="1" portprefix="/teo" xmlns:xi="http://www.w3.org/2001/XInclude">
<devices>
<xi:include href="./teo-devices.xml" />
</devices>
</robot> teo-devices.xml: <?xml version="1.0" encoding="UTF-8"?>
<device name="my-device" type="MyDevice">
<param name="name1">value1</param>
<group name="GROUP1">
<param name="name2">value2</param>
</group>
<paramlist name="networks">
<elem name="head_joints1">( 0 1 0 1 )</elem>
<elem name="head_joints2">( 2 5 0 3 )</elem>
</paramlist>
<!-- <param name="name1">value3</param> --> <!-- ERROR: duplicate param name -->
<xi:include href="./params.xml" />
<params>
<param name="name2">value4</param>
<group name="GROUP2">
<param name="name3">value5</param>
</group>
</params>
</device> params.xml: <?xml version="1.0" encoding="UTF-8"?>
<params>
<param name="name4">value5</param>
<group name="GROUP3">
<param name="name5">value6</param>
</group>
</params> The See also this example project with a dummy plugin used to show how parameters are passed to it during initial configuration. Usage: |
To increase flexibility, e.g. launch different robot parts depending on a set of context files as in launchCanBus, use For instance, let's say we have config "config.xml" The command |
Given: <!-- config.xml -->
<!-- ... -->
<param name="name1" extern-name="name2">value</param>
<!-- ... -->
while
|
<xi:include href="./test1.xml" enabled_by="a1 a2" />
<xi:include href="./test2.xml" disabled_by="b1 b2" />
<param name="default" extern-name="custom">()</param> Since |
It is possible to invoke
#include <array>
#include <yarp/os/LogStream.h>
#include <yarp/os/ResourceFinder.h>
#include <yarp/robotinterface/XMLReader.h>
int main()
{
auto & rf = yarp::os::ResourceFinder::getResourceFinderSingleton();
auto path = rf.findFileByName("config.xml");
if (path.empty())
{
yError() << "Could not find config.xml";
return 1;
}
std::array arr {16, 22, 37, 46, 53};
auto * arrPtr = &arr;
yarp::os::Property options;
options.put("enable_tags", yarp::os::Value::makeList("a1"));
options.put("myparam", yarp::os::Value::makeList("1 8 9"));
options.put("myexternblob", yarp::os::Value::makeBlob(&arrPtr, sizeof(arrPtr)));
yarp::robotinterface::XMLReader reader;
auto result = reader.getRobotFromFile(path, options);
if (!result.parsingIsSuccessful)
{
yError() << "Could not parse config.xml";
return 1;
}
bool ok = true;
ok &= result.robot.enterPhase(yarp::robotinterface::ActionPhaseStartup);
ok &= result.robot.enterPhase(yarp::robotinterface::ActionPhaseInterrupt1);
ok &= result.robot.enterPhase(yarp::robotinterface::ActionPhaseShutdown);
return ok ? 0 : 1;
}
#include "MyDevice.hpp"
#include <array>
#include <iostream>
#include <yarp/os/Bottle.h>
bool MyDevice::open(yarp::os::Searchable & config)
{
yarp::os::Bottle b("{" + yarp::os::Bottle(config.toString()).findGroup("myblob").tail().toString() + "}");
const auto * arr = *reinterpret_cast<std::array<int, 5> * const *>(b.get(0).asBlob());
for (const auto & elem : *arr)
{
std::cout << elem << std::endl;
}
return true;
} Note the mess around passing a blob to the underlying device through yarprobotinterface. The convolute Test project: yarprobotinterface.zip. Edit: blob support proposed at robotology/yarp#3066. |
The For instance, this is not allowed if <devices>
<xi:include href="./mydevice.xml" disabled_by="no_mydevice" />
<device name="mywrapper" type="mywrapper_nws">
<action phase="startup" level="1" type="attach">
<param name="device">mydevice</param>
</action>
</device>
</devices> The It could be circumvented like so: <devices>
<xi:include href="./mydevice.xml" disabled_by="no_mydevice" />
<device name="mywrapper" type="mywrapper_nws">
<action phase="startup" level="1" type="attach">
<xi:include href="./mydevice-param.xml" disabled_by="no_mydevice" />
</action>
</device>
</devices> With <params>
<param name="device">mydevice</param>
</params> So I was thinking of a similar mechanism to conditionally disable broken nodes through To avoid this madness, I'm considering an |
Besides,
Less messy, but forces I'm considering this intermediate solution: <devices>
<xi:include href="./idxx-ipos.xml" disabled_by="no_idxx" />
<xi:include href="./fake-idxx-ipos.xml" enabled_by="no_idxx" />
<device name="mywrapper" type="mywrapper_nws">
<action phase="startup" level="1" type="attach">
<param name="device">idxx</param>
</action>
</device>
</devices>
<!-- idxx-ipos.xml -->
<device name="idxx" type="TechnosoftIpos"></device>
<!-- fake-idxx-ipos.xml -->
<device name="idxx" type="FakeJoint"></device> Despite requiring a lot of boilerplate XML files, Since Edit: I forgot that for this to work, one would need to issue |
Recap of available options:
|
I'm going with 2.ii.b. To ease the handling of fake devices, I'm no longer supporting CanBusFake to focus mainly on FakeJoint instead. A virtual CAN controller may be used for testing, see #251 (comment):
Please do note default WSL(2) does not support virtual CAN. A custom kernel must be compiled for this to work, see microsoft/WSL#5533. Besides that, since real devices might be replaced by fake ones, but instantiated anyway, the former should never perform any CAN comms nor start threads in |
Our launchCanBus app is the main entry point to orchestrating CAN control boards and their wrapped raw subdevices according to the requested configuration in the .ini format. It was devised as an ad hoc solution, apparently superior to the (at the time undocumented) yarprobotinterface tool, see #237. Yet times have changed and we already benefit from the latter when using Gazebo. In my experience, the syntax feels cleaner and the document structure favors adhering to the increasingly more common device attach methodology for wrappers, while doing so in a descriptive fashion (this is currently encoded in launchCanBus's code). Besides, there would be a sensible gain in flexibility we haven't experienced yet in terms of file transclusion via
<xi:include>
and the handy tag mechanism described here (watch out for conditionally enabled ROS(2) stuff). There are lots of XML file examples at robotology/robots-configuration.Proposal: drop launchCanBus in favor of yarprobotinterface, migrate our INI files to the XML format supported by the latter.
The text was updated successfully, but these errors were encountered: