RcsPySim
A robot control and simulation library
AMIntegrate1stOrder.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright (c) 2020, Fabio Muratore, Honda Research Institute Europe GmbH, and
3  Technical University of Darmstadt.
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions are met:
8  1. Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  2. Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  3. Neither the name of Fabio Muratore, Honda Research Institute Europe GmbH,
14  or Technical University of Darmstadt, nor the names of its contributors may
15  be used to endorse or promote products derived from this software without
16  specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  DISCLAIMED. IN NO EVENT SHALL FABIO MURATORE, HONDA RESEARCH INSTITUTE EUROPE GMBH,
22  OR TECHNICAL UNIVERSITY OF DARMSTADT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
26  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  POSSIBILITY OF SUCH DAMAGE.
29 *******************************************************************************/
30 
31 #include "AMIntegrate1stOrder.h"
32 
33 #include "../util/integrator.h"
34 
35 #include <Rcs_VecNd.h>
36 
37 namespace Rcs
38 {
39 
41  ActionModel(wrapped->getGraph()),
42  wrapped(wrapped)
43 {
44  // Create integrator state storage
45  integrated_action = MatNd_create(wrapped->getDim(), 1);
46 
47  // Store max_action
48  this->maxAction = MatNd_create(wrapped->getDim(), 1);
49  VecNd_setElementsTo(this->maxAction->ele, maxAction, wrapped->getDim());
50 }
51 
53 {
54  MatNd_destroy(integrated_action);
55  delete wrapped;
56 }
57 
58 unsigned int AMIntegrate1stOrder::getDim() const
59 {
60  return wrapped->getDim();
61 }
62 
63 void AMIntegrate1stOrder::getMinMax(double* min, double* max) const
64 {
65  VecNd_constMul(min, maxAction->ele, -1, getDim());
66  VecNd_copy(max, maxAction->ele, getDim());
67 }
68 
69 std::vector<std::string> AMIntegrate1stOrder::getNames() const
70 {
71  auto wnames = wrapped->getNames();
72  // add the suffix 'd' to every var to signal that it's the first order derivative
73  for (auto& name : wnames) {
74  name += "d";
75  }
76  return wnames;
77 }
78 
79 void AMIntegrate1stOrder::computeCommand(MatNd* q_des, MatNd* q_dot_des, MatNd* T_des, const MatNd* action, double dt)
80 {
81  // perform integration
83 
84  // pass integrated values to wrapped
85  wrapped->computeCommand(q_des, q_dot_des, T_des, integrated_action, dt);
86 }
87 
89 {
90  wrapped->reset();
91  // reset integrator state to current (initial)
93 }
94 
95 void AMIntegrate1stOrder::getStableAction(MatNd* action) const
96 {
97  // velocity of 0 is stable
98  MatNd_setZero(action);
99 }
100 
102 {
103  return wrapped;
104 }
105 
106 ActionModel* AMIntegrate1stOrder::clone(RcsGraph* newGraph) const
107 {
108  return new AMIntegrate1stOrder(wrapped->clone(newGraph), maxAction->ele[0]);
109 }
110 
111 } /* namespace Rcs */
virtual std::vector< std::string > getNames() const
virtual void computeCommand(MatNd *q_des, MatNd *q_dot_des, MatNd *T_des, const MatNd *action, double dt)
virtual void getMinMax(double *min, double *max) const
virtual ActionModel * getWrappedActionModel() const
virtual void computeCommand(MatNd *q_des, MatNd *q_dot_des, MatNd *T_des, const MatNd *action, double dt)=0
virtual unsigned int getDim() const
virtual std::vector< std::string > getNames() const
AMIntegrate1stOrder(ActionModel *wrapped, double maxAction)
virtual void reset()
Definition: ActionModel.cpp:49
ActionModel * clone() const
Definition: ActionModel.h:72
void intStep1stOrder(MatNd *x, const MatNd *xd_0, const MatNd *xd_T, double dt, IntMode mode)
Definition: integrator.cpp:65
virtual void getStableAction(MatNd *action) const
virtual unsigned int getDim() const =0
virtual void getStableAction(MatNd *action) const =0