Example

This examples builds on the Oncilla API Level 0, which is the lowest Oncilla interface level. The example was written for the Oncilla Simulation, but should work exactly the same later on the real hardware platform.

Simple Sine Movement

To show basic movement using the Oncilla interface, we provide a simple example performing a sine-movement on the Oncilla joint in position control, to generate a simple walking movement.

The source code below shows the example implementation. To perform the simple movement the following basic steps are done:

  1. The actual robot object is instantiated (line 25). This connect either to the simulation backend or the real hardware.
  2. We then grab the Synchronizer so that in the case of Simulation we can control the actual stepping of the Simulator by our own (line 29).
  3. We take the joints we want to use for the movement, in this case the Oncilla joints L1 and L2 and give them meaningful names.
  4. To perform the actual movement we generate the desired JointAngles and set them as new position in the joints (e.g. lines 62-63).
  5. After we set new commands, we perform one simulation step (line 75) to let the commands have effect and to get current sensor values.
  6. To not work with the real-world time, but with the simulated time, we integrate a time variable with the processed time reported by the simulation (line 57).
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <rsc/misc/langutils.h>

#include <rci/dto/JointAngles.h>

#include "liboncilla/Oncilla.h"


using namespace std;
using namespace boost;

using namespace rci;
using namespace rci::oncilla;

double hip_position(double phase, double amplitude, double offset) {
    return amplitude * std::cos(phase) + offset;
}

double knee_position(double phase, double phase_lag, double amplitude,
        double offset) {
    return amplitude * ((phase + phase_lag) > M_PI ? 1.0 : 0.0) + offset;
}

int main() {

    // Instantiate the actual robot object
    Oncilla oncilla;

	// Get the synchronizer, so that we can control the actual simulation
	// stepping from within our code
	::rci::oncilla::Synchronizer::Ptr synchronizer = oncilla.getSynchronizer();

	// Get all the joints we are interested in - L1 and L2
	L1::Ptr left_fore_hip = oncilla.getL1(LEFT_FORE);
	L2::Ptr left_fore_knee = oncilla.getL2(LEFT_FORE);
	L1::Ptr right_fore_hip = oncilla.getL1(RIGHT_FORE);
	L2::Ptr right_fore_knee = oncilla.getL2(RIGHT_FORE);
	L1::Ptr left_hind_hip = oncilla.getL1(LEFT_HIND);
	L2::Ptr left_hind_knee = oncilla.getL2(LEFT_HIND);
	L1::Ptr right_hind_hip = oncilla.getL1(RIGHT_HIND);
	L2::Ptr right_hind_knee = oncilla.getL2(RIGHT_HIND);

    //sets some parameter for the sinewave
    double hip_amplitude(30),
            fore_hip_offset(0),
            hind_hip_offset(0),
            fore_knee_amplitude(1),
            fore_knee_offset(0),
            hind_knee_amplitude(1),
            hind_knee_offset(0),
            fore_hip_knee_phase_lag(0),
            hind_hip_knee_phase_lag(0),
            frequency(1);
    double time_s, phase, antiphase;

    time_s = 0;
    while (true) {
        // The simulated time is our phase
        time_s += synchronizer->lastProcessTimeStep();
        phase = std::fmod(time_s * frequency * 2 * M_PI, 2 * M_PI);

        antiphase = std::fmod(phase + M_PI, 2 * M_PI);

        left_fore_hip->setJointPosition(JointAngles::fromDeg(hip_position(phase, hip_amplitude, fore_hip_offset)));
        left_fore_knee->setJointPosition(JointAngles::fromRad(knee_position(phase, fore_hip_knee_phase_lag,fore_knee_amplitude, fore_knee_offset)));

        right_fore_hip->setJointPosition(JointAngles::fromDeg(hip_position(antiphase, hip_amplitude,fore_hip_offset)));
        right_fore_knee->setJointPosition(JointAngles::fromRad(knee_position(antiphase, fore_hip_knee_phase_lag,fore_knee_amplitude, fore_knee_offset)));

        left_hind_hip->setJointPosition(JointAngles::fromDeg(hip_position(antiphase, hip_amplitude,hind_hip_offset)));
        left_hind_knee->setJointPosition(JointAngles::fromRad(knee_position(antiphase, hind_hip_knee_phase_lag,hind_knee_amplitude, hind_knee_offset)));

        right_hind_hip->setJointPosition(JointAngles::fromDeg(hip_position(phase, hip_amplitude, hind_hip_offset)));
        right_hind_knee->setJointPosition(JointAngles::fromRad(knee_position(phase, hind_hip_knee_phase_lag,hind_knee_amplitude, hind_knee_offset)));

        // Perform a (simulation) processing step
        synchronizer->process();
    }

    return EXIT_SUCCESS;
}

...

Table of Contents

Related Documentation

This Page