humotion / src / server / reflexxes_motion_generator.cpp @ 14831938
History | View | Annotate | Download (4.026 KB)
1 | 8c6c1163 | Simon Schulz | /*
|
---|---|---|---|
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 | 0c8d22a5 | sschulz | #include "humotion/server/eye_motion_generator.h" |
29 | 8c6c1163 | Simon Schulz | |
30 | 0c8d22a5 | sschulz | using humotion::server::ReflexxesMotionGenerator;
|
31 | 6d13138a | sschulz | using humotion::server::Config;
|
32 | 8c6c1163 | Simon Schulz | |
33 | //! constructor
|
||
34 | 6d13138a | sschulz | ReflexxesMotionGenerator::ReflexxesMotionGenerator(JointInterface *j, Config *c, int dof, float t) : |
35 | MotionGenerator(j, c) { |
||
36 | 8c6c1163 | Simon Schulz | dof_count = dof; |
37 | |||
38 | 0c8d22a5 | sschulz | // create Reflexxes API for <dof> DOF actuator
|
39 | 8c6c1163 | Simon Schulz | reflexxes_api = new ReflexxesAPI(dof, t);
|
40 | reflexxes_position_input = new RMLPositionInputParameters(dof);
|
||
41 | reflexxes_position_output = new RMLPositionOutputParameters(dof);
|
||
42 | |||
43 | 0c8d22a5 | sschulz | // synchronize phase
|
44 | reflexxes_motion_flags.SynchronizationBehavior = |
||
45 | RMLPositionFlags::PHASE_SYNCHRONIZATION_IF_POSSIBLE; |
||
46 | 8c6c1163 | Simon Schulz | } |
47 | |||
48 | //! destructor
|
||
49 | 0c8d22a5 | sschulz | ReflexxesMotionGenerator::~ReflexxesMotionGenerator() { |
50 | 8c6c1163 | Simon Schulz | } |
51 | |||
52 | //! feed motion generator with target data:
|
||
53 | //! \param dof id
|
||
54 | //! \param target angle
|
||
55 | //! \param max_speed max reachable speed during accel
|
||
56 | //! \param max_accel max allowable acceleration
|
||
57 | 730467d3 | Simon Schulz | void ReflexxesMotionGenerator::reflexxes_set_input(int dof, float target, |
58 | 0c8d22a5 | sschulz | float current_position, float current_velocity, |
59 | 730467d3 | Simon Schulz | humotion::Timestamp timestamp, |
60 | 0c8d22a5 | sschulz | float max_speed, float max_accel) { |
61 | 21444915 | Simon Schulz | assert(dof < dof_count); |
62 | |||
63 | 45345055 | Simon Schulz | // set up reflexxes control loop
|
64 | 8c6c1163 | Simon Schulz | reflexxes_position_input->TargetPositionVector->VecData[dof] = target; |
65 | reflexxes_position_input->SelectionVector->VecData[dof] = true;
|
||
66 | reflexxes_position_input->MaxVelocityVector->VecData[dof] = max_speed; |
||
67 | 21444915 | Simon Schulz | reflexxes_position_input->MaxAccelerationVector->VecData[dof] = max_accel; |
68 | 0c8d22a5 | sschulz | |
69 | // target speed is zero (really?)
|
||
70 | reflexxes_position_input->TargetVelocityVector->VecData[dof] = 0.0; |
||
71 | 730467d3 | Simon Schulz | |
72 | 21444915 | Simon Schulz | // safety: libreflexxes does not like zero accellerations...
|
73 | 0c8d22a5 | sschulz | if (reflexxes_position_input->MaxAccelerationVector->VecData[dof] == 0.0) { |
74 | 21444915 | Simon Schulz | reflexxes_position_input->MaxAccelerationVector->VecData[dof] = 0.0001; |
75 | } |
||
76 | 8c6c1163 | Simon Schulz | } |
77 | |||
78 | 0d0f5ca1 | Simon Schulz | |
79 | 8c6c1163 | Simon Schulz | //! calculate motion profile
|
80 | |||
81 | 0c8d22a5 | sschulz | void ReflexxesMotionGenerator::reflexxes_calculate_profile() {
|
82 | int res = reflexxes_api->RMLPosition(*reflexxes_position_input,
|
||
83 | reflexxes_position_output, reflexxes_motion_flags); |
||
84 | 8c6c1163 | Simon Schulz | |
85 | 0c8d22a5 | sschulz | if (res < 0) { |
86 | if (res == ReflexxesAPI::RML_ERROR_INVALID_INPUT_VALUES) {
|
||
87 | printf("> ReflexxesMotionGenerator --> RML_ERROR_INVALID_INPUT_VALUES error\n");
|
||
88 | } else {
|
||
89 | printf("> ReflexxesMotionGenerator --> UNKNOWN_ERROR: reflexxes error %d\n", res);
|
||
90 | 8c6c1163 | Simon Schulz | } |
91 | } |
||
92 | |||
93 | 45345055 | Simon Schulz | // feed back values
|
94 | 0c8d22a5 | sschulz | for (int i = 0; i < dof_count; i++) { |
95 | reflexxes_position_input->CurrentPositionVector->VecData[i] = |
||
96 | reflexxes_position_output->NewPositionVector->VecData[i]; |
||
97 | |||
98 | reflexxes_position_input->CurrentVelocityVector->VecData[i] = |
||
99 | reflexxes_position_output->NewVelocityVector->VecData[i]; |
||
100 | |||
101 | reflexxes_position_input->CurrentAccelerationVector->VecData[i] = |
||
102 | reflexxes_position_output->NewAccelerationVector->VecData[i]; |
||
103 | 8c6c1163 | Simon Schulz | } |
104 | } |