Skip to content
This repository has been archived by the owner on Feb 21, 2021. It is now read-only.

[issue #892] Created Config library for read Yaml config files #916

Merged
merged 15 commits into from
Oct 4, 2017

Conversation

aitormf
Copy link
Collaborator

@aitormf aitormf commented Sep 29, 2017

In this PR I maked 2 new libraries (config_cpp and config_py) to read Yaml config files. in their directories you can find a demo programs to show how can you use those libraries.

C++:

#include 
...
Config::Properties props = Config::load(argc, argv);
std::cout << props << std::endl;
std::cout << props.asString("Demo.Motors.Proxy")<< std::endl;
std::cout << props.asStringWithDefault("Demo.Motors.Proxy2", "Proxy2")<< std::endl;

Python:

import config
....
cfg = config.load(sys.argv[1])

print (cfg.getProperty("Demo.Motors.Server"))
print (cfg.getPropertyWithDefault("Demo.Motors.Server2", "Server2"))
print cfg

a example of new config files is the following:

Demo:
  Motors:
    Server: 2 # 0 -> Deactivate, 1 -> Ice , 2 -> ROS
    Proxy: "Motors:default -h localhost -p 9001"
    Topic: "/turtlebotROS/mobile_base/commands/velocity"
    Name: basic_component_pyCamera
    maxW: 0.7
    maxV: 4
  
  Camera:
    Server: 2 # 0 -> Deactivate, 1 -> Ice , 2 -> ROS
    Proxy: "CameraL:default -h localhost -p 9001"
    Format: RGB8
    Topic: "/TurtlebotROS/cameraL/image_raw"
    Name: basic_component_pyCamera

  NodeName: demo

JdeRobotComm (py and C++) has also been modified:

  • Updated to use config library
  • changed name from JdeRobotComm to Comm

Python

import config
import comm
...
cfg = config.load(sys.argv[1])
jdrc= comm.init(cfg, "Test")
client = jdrc.getCameraClient("Test.Camera1")

C++

#include "jderobot/config/config.h"
#include "jderobot/comm/communicator.hpp"
#include 
...
Config::Properties props = Config::load(argc, argv);

Comm::Communicator* jdrc = new Comm::Communicator(props);
Comm::CameraClient* camera1 = Comm::getCameraClient(jdrc, "kobukiViewer.Camera1");

@fqez fqez merged commit 325cf47 into JdeRobot:master Oct 4, 2017
@aitormf aitormf mentioned this pull request Oct 5, 2017
@okanasik
Copy link
Contributor

okanasik commented Oct 5, 2017

Dear @aitormf, I have a quick question about the yaml config. For the components we have three constructs about ice interfaces; interface, proxyName, name. Which part of these corresponds to values of yaml values?

For the following example:

Demo:
  Motors:
    Server: 2 # 0 -> Deactivate, 1 -> Ice , 2 -> ROS
    Proxy: "Motors:default -h localhost -p 9001"
    Topic: "/turtlebotROS/mobile_base/commands/velocity"
    Name: basic_component_pyCamera
    maxW: 0.7
    maxV: 4

Motors just under demo is interface, Motors inside Proxy is proxyName, name is the Name:
If that's correct. Can we define two Motors interface? I am not sure, but that should not be possible with that config structure. What do you think?

@aitormf
Copy link
Collaborator Author

aitormf commented Oct 6, 2017

Hi @okanasik, yes, fields are as you say, but if you want, you can have two motor interfaces, for example kobukiViewer tool has a two camera interfaces and its config file is the following:

kobukiViewer:
  Motors:
    Server: 1 # 0 -> Deactivate, 1 -> Ice , 2 -> ROS
    Proxy: "Motors:default -h localhost -p 9001"
    Topic: "/turtlebotROS/mobile_base/commands/velocity"
    Name: kobukiViewerMotors
    maxV: 3
    maxW: 0.7

  Camera1:
    Server: 1 # 0 -> Deactivate, 1 -> Ice , 2 -> ROS
    Proxy: "CameraL:default -h localhost -p 9001"
    Format: RGB8
    Topic: "/TurtlebotROS/cameraL/image_raw"
    Name: kobukiViewerCamera1

  Camera2:
    Server: 1 # 0 -> Deactivate, 1 -> Ice , 2 -> ROS
    Proxy: "CameraR:default -h localhost -p 9001"
    Format: RGB8
    Topic: "/TurtlebotROS/cameraR/image_raw"
    Name: kobukiViewerCamera2

  Pose3D:
    Server: 1 # 0 -> Deactivate, 1 -> Ice , 2 -> ROS
    Proxy: "Pose3D:default -h localhost -p 9001"
    Topic: "//turtlebotROS/odom"
    Name: kobukiViewerPose3d

  Laser:
    Server: 1 # 0 -> Deactivate, 1 -> Ice , 2 -> ROS
    Proxy: "Laser:default -h localhost -p 9001"
    Topic: "/turtlebotROS/laser/scan"
    Name: kobukiViewerLaser

  Vmax: 3
  Wmax: 0.7
  NodeName: kobukiViewer

With motors would be the same.
I hope I helped you

@okanasik
Copy link
Contributor

okanasik commented Oct 6, 2017

Thanks @aitormf , The config dialog of visualStates was directly using interface to determine the type of comm client that will be instantiated. In that case, I can add indexes for every interface.

Best.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants