property/main.cpp

How to read a configuration file. This example is designed to read a file like the following (property/config.txt):

//
// Initialization file for robot head, 8 dof on can bus controller.
//


[GENERAL] 
Joints 8
MaxDAC 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0

AxisMap 1 7 0 6 2 3 5 4
Encoder 360.0 360.0 360.0 360.0 360.0 360.0 360.0 360.0
Zeros 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
Signs 0 0 0 0 0 0 0 0
Stiff 1 1 1 1 1 1 1 1
CurrentLimits 1220.0 1220.0 1220.0 1220.0 10000.0 10000.0 10000.0 10000.0

CanAddresses 14 13 12 11 128 128 128 128 128 128 128 128 128 128 128 128


// limits are: neck pan, neck tilt, eye tilt, version, vergence
[LIMITS]
Max 250000 250000 250000 250000 250000 180000 180000 180000
Min -250000 -250000 -250000 -250000 -250000 -180000 -180000 -180000

[HIGHPID]
Pid0 32 128 2 0 0 1333 0 1333 4 0
Pid1 32 128 2 0 0 1333 0 1333 4 0
Pid2 32 128 2 0 0 1333 0 1333 4 0
Pid3 32 128 2 0 0 1333 0 1333 4 0
Pid4 32 128 4 0 0 1333 0 1333 4 0
Pid5 32 128 1 0 0 1333 0 1333 4 0
Pid6 32 128 1 0 0 1333 0 1333 4 0
Pid7 32 128 1 0 0 1333 0 1333 4 0

[LOWPID]
Pid0 0 0 0 0 0 32767 0 32767 0 0
Pid1 0 0 0 0 0 32767 0 32767 0 0
Pid2 0 0 0 0 0 32767 0 32767 0 0
Pid3 0 0 0 0 0 32767 0 32767 0 0
Pid4 0 0 0 0 0 32767 0 32767 0 0
Pid5 0 0 0 0 0 32767 0 32767 0 0
Pid6 0 0 0 0 0 32767 0 32767 0 0
Pid7 0 0 0 0 0 32767 0 32767 0 0
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
#include <stdio.h>
#include <stdlib.h>

#include <yarp/os/Property.h>

using namespace yarp::os;

int main(int argc, char *argv[]) {
    Property cmdLine;
    cmdLine.fromCommand(argc,argv);

    if (!cmdLine.check("file")) {
        printf("Please call with: --file config.txt\n");
        exit(1);
    }
    ConstString fname = cmdLine.find("file").asString();
    printf("Working with config file %s\n", fname.c_str());

    Property robot;
    robot.fromConfigFile(fname.c_str());
    if (!robot.check("GENERAL")) {
        printf("Cannot understand config file\n");
        exit(1);
    }

    int joints = robot.findGroup("GENERAL").find("Joints").asInt();
    printf("Robot has %d joints\n", joints);

    Bottle& maxes = robot.findGroup("LIMITS").findGroup("Max");
    printf("Robot has limits: ");
    for (int i=1; i<maxes.size(); i++) {
        printf("%d ", maxes.get(i).asInt());
    }
    printf("\n");

    //printf("If you wanted to transmit this configuration, here it is in Bottle format:\n");
    //printf("%s\n", robot.toString().c_str());

    return 0;
}
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines