Statistics
| Branch: | Tag: | Revision:

humotion / src / server / reflexxes_motion_generator.cpp @ 0c8d22a5

History | View | Annotate | Download (3.981 KB)

1
/*
2
* This file is part of humotion
3
*
4
* Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
* http://opensource.cit-ec.de/projects/humotion
6
*
7
* This file may be licensed under the terms of the
8
* GNU Lesser General Public License Version 3 (the ``LGPL''),
9
* or (at your option) any later version.
10
*
11
* Software distributed under the License is distributed
12
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
* express or implied. See the LGPL for the specific language
14
* governing rights and limitations.
15
*
16
* You should have received a copy of the LGPL along with this
17
* program. If not, go to http://www.gnu.org/licenses/lgpl.html
18
* or write to the Free Software Foundation, Inc.,
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
*
21
* The development of this software was supported by the
22
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
* The Excellence Cluster EXC 277 is a grant of the Deutsche
24
* Forschungsgemeinschaft (DFG) in the context of the German
25
* Excellence Initiative.
26
*/
27

    
28
#include "humotion/server/eye_motion_generator.h"
29

    
30
using humotion::server::ReflexxesMotionGenerator;
31

    
32
//! constructor
33
ReflexxesMotionGenerator::ReflexxesMotionGenerator(JointInterface *j, int dof, float t) :
34
    MotionGenerator(j) {
35
    dof_count = dof;
36

    
37
    // create Reflexxes API for <dof> DOF actuator
38
    reflexxes_api = new ReflexxesAPI(dof, t);
39
    reflexxes_position_input  = new RMLPositionInputParameters(dof);
40
    reflexxes_position_output = new RMLPositionOutputParameters(dof);
41

    
42
    // synchronize phase
43
    reflexxes_motion_flags.SynchronizationBehavior =
44
            RMLPositionFlags::PHASE_SYNCHRONIZATION_IF_POSSIBLE;
45
}
46

    
47
//! destructor
48
ReflexxesMotionGenerator::~ReflexxesMotionGenerator() {
49
}
50

    
51
//! feed motion generator with target data:
52
//! \param dof id
53
//! \param target angle
54
//! \param max_speed max reachable speed during accel
55
//! \param max_accel max allowable acceleration
56
void ReflexxesMotionGenerator::reflexxes_set_input(int dof, float target,
57
                                                   float current_position, float current_velocity,
58
                                                   humotion::Timestamp timestamp,
59
                                                   float max_speed, float max_accel) {
60
    assert(dof < dof_count);
61

    
62
    // set up reflexxes control loop
63
    reflexxes_position_input->TargetPositionVector->VecData[dof]  = target;
64
    reflexxes_position_input->SelectionVector->VecData[dof]       = true;
65
    reflexxes_position_input->MaxVelocityVector->VecData[dof]     = max_speed;
66
    reflexxes_position_input->MaxAccelerationVector->VecData[dof] = max_accel;
67

    
68
    // target speed is zero (really?)
69
    reflexxes_position_input->TargetVelocityVector->VecData[dof]  = 0.0;
70

    
71
    // safety: libreflexxes does not like zero accellerations...
72
    if (reflexxes_position_input->MaxAccelerationVector->VecData[dof] == 0.0) {
73
            reflexxes_position_input->MaxAccelerationVector->VecData[dof] = 0.0001;
74
    }
75
}
76

    
77

    
78
//! calculate motion profile
79

    
80
void ReflexxesMotionGenerator::reflexxes_calculate_profile() {
81
    int res = reflexxes_api->RMLPosition(*reflexxes_position_input,
82
                                         reflexxes_position_output, reflexxes_motion_flags);
83

    
84
    if (res < 0) {
85
        if (res == ReflexxesAPI::RML_ERROR_INVALID_INPUT_VALUES) {
86
            printf("> ReflexxesMotionGenerator --> RML_ERROR_INVALID_INPUT_VALUES error\n");
87
        } else {
88
            printf("> ReflexxesMotionGenerator --> UNKNOWN_ERROR: reflexxes error %d\n", res);
89
        }
90
    }
91

    
92
    // feed back values
93
    for (int i = 0; i < dof_count; i++) {
94
        reflexxes_position_input->CurrentPositionVector->VecData[i]     =
95
                reflexxes_position_output->NewPositionVector->VecData[i];
96

    
97
        reflexxes_position_input->CurrentVelocityVector->VecData[i]     =
98
                reflexxes_position_output->NewVelocityVector->VecData[i];
99

    
100
        reflexxes_position_input->CurrentAccelerationVector->VecData[i] =
101
                reflexxes_position_output->NewAccelerationVector->VecData[i];
102
    }
103
}