RcsPySim
A robot control and simulation library
AMPlateAngPos.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 "AMPlateAngPos.h"
32 
33 #include <Rcs_macros.h>
34 //#include <TaskPose6D.h>
35 #include <TaskPosition3D.h>
36 #include <TaskGenericEuler3D.h>
37 
38 namespace Rcs
39 {
40 
42 {
43  // lookup plate body on desired state graph
44  RcsBody* plate = RcsGraph_getBodyByName(desiredGraph, "Plate");
45  RCHECK(plate);
46  // add the dynamicalSystems
47  addTask(new TaskPosition3D(desiredGraph, plate, NULL, NULL));
48  addTask(new TaskGenericEuler3D(desiredGraph, "CABr", plate, NULL, NULL));
49 
50  // Create state matrix, and init with current
51  x_des = MatNd_create(getController()->getTaskDim(), 1);
52  getController()->computeX(x_des);
53 }
54 
56 {
57  MatNd_destroy(x_des);
58 }
59 
60 unsigned int AMPlateAngPos::getDim() const
61 {
62  return 2;
63 }
64 
65 void AMPlateAngPos::getMinMax(double* min, double* max) const
66 {
67  double maxAngle = 45*M_PI/180;
68  min[0] = -maxAngle;
69  min[1] = -maxAngle;
70  max[0] = maxAngle;
71  max[1] = maxAngle;
72 }
73 
74 std::vector<std::string> AMPlateAngPos::getNames() const
75 {
76  return {"a", "b"};
77 }
78 
80  MatNd* q_des, MatNd* q_dot_des, MatNd* T_des,
81  const MatNd* action, double dt)
82 {
83  // copy actions into relevant parts of x_des
84  x_des->ele[4] = action->ele[0]; // alpha
85  x_des->ele[5] = action->ele[1]; // beta
86 
87  // use IK to compute q_des
88  computeIK(q_des, q_dot_des, T_des, x_des, dt);
89 }
90 
92 {
94 
95  // Init the desired state
96  getController()->computeX(x_des);
97 }
98 
99 void AMPlateAngPos::getStableAction(MatNd* action) const
100 {
101  MatNd* x_curr = NULL;
102  MatNd_create2(x_curr, getController()->getTaskDim(), 1);
103  // compute current state
104  getController()->computeX(x_curr);
105  // export relevant parts of action
106  action->ele[0] = x_curr->ele[4]; // alpha
107  action->ele[1] = x_curr->ele[5]; // beta
108  // cleanup
109  MatNd_destroy(x_curr);
110 }
111 
112 ActionModel* AMPlateAngPos::clone(RcsGraph* newGraph) const
113 {
114  auto res = new AMPlateAngPos(newGraph);
115  res->setupCollisionModel(collisionMdl);
116  return res;
117 }
118 
119 } /* namespace Rcs */
120 
virtual void reset()
virtual std::vector< std::string > getNames() const
virtual ~AMPlateAngPos()
virtual void getStableAction(MatNd *action) const
void addTask(Task *task)
RcsGraph * desiredGraph
AMPlateAngPos(RcsGraph *graph)
virtual void getMinMax(double *min, double *max) const
virtual unsigned int getDim() const
virtual void computeCommand(MatNd *q_des, MatNd *q_dot_des, MatNd *T_des, const MatNd *action, double dt)
void computeIK(MatNd *q_des, MatNd *q_dot_des, MatNd *T_des, const MatNd *x_des, double dt)
RcsCollisionMdl * collisionMdl
virtual void reset()
ActionModel * clone() const
Definition: ActionModel.h:72
const ControllerBase * getController() const
Definition: ActionModelIK.h:76