RcsPySim
A robot control and simulation library
AMPlatePos5D.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 "AMPlatePos5D.h"
32 
33 #include <TaskPosition3D.h>
34 #include <TaskEuler3D.h>
35 
36 #include <Rcs_macros.h>
37 #include <Rcs_VecNd.h>
38 #include <Rcs_HTr.h>
39 #include <Rcs_typedef.h>
40 
41 
42 namespace Rcs
43 {
44 const unsigned int PLATE_TASK_DIM = 6;
45 
46 AMPlatePos5D::AMPlatePos5D(RcsGraph* graph) : ActionModelIK(graph)
47 {
48  // lookup plate body on desired state graph
49  RcsBody* plate = RcsGraph_getBodyByName(desiredGraph, "Plate");
50  RCHECK(plate);
51 
52  // the plate position is computed relative to a marker frame, which is set to
53  // the plate's initial position on startup.
54  RcsBody* plateOrigMarker = RcsGraph_getBodyByName(desiredGraph, "PlateOriginMarker");
55  RCHECK_MSG(plateOrigMarker, "PlateOriginMarker is missing, please update your xml.");
56  // set origin marker position
57  HTr_copyOrRecreate(&plateOrigMarker->A_BP, plate->A_BI);
58 
59  // create dynamicalSystems relative to origin marker
60  addTask(new TaskPosition3D(desiredGraph, plate, plateOrigMarker, NULL));
61  addTask(new TaskEuler3D(desiredGraph, plate, plateOrigMarker, NULL));
62  RCHECK_EQ(PLATE_TASK_DIM, getController()->getTaskDim());
63 }
64 
66 {
67 }
68 
69 unsigned int AMPlatePos5D::getDim() const
70 {
71  return 5;
72 }
73 
74 void AMPlatePos5D::getMinMax(double* min, double* max) const
75 {
76  // separate maximal divergence for XY movement, Z movement and angular movement.
77 
78  double maxXY = 0.5;
79  min[0] = -maxXY;
80  min[1] = -maxXY;
81  max[0] = maxXY;
82  max[1] = maxXY;
83 
84  double maxZ = 0.5;
85  min[2] = -maxZ;
86  max[2] = maxZ;
87 
88  double maxAngle = 45*M_PI/180;
89  min[4] = -maxAngle;
90  min[5] = -maxAngle;
91  max[4] = maxAngle;
92  max[5] = maxAngle;
93 }
94 
95 std::vector<std::string> AMPlatePos5D::getNames() const
96 {
97  return {"x", "y", "z", "a", "b"};
98 }
99 
100 void AMPlatePos5D::computeCommand(MatNd* q_des, MatNd* q_dot_des, MatNd* T_des, const MatNd* action, double dt)
101 {
102  // expand action into state matrix by adding the desired Z rotation which is always 0
103  MatNd* x_des;
104  MatNd_fromStack(x_des, PLATE_TASK_DIM, 1);
105  VecNd_copy(x_des->ele, action->ele, 5);
106 
107  // delegate to IK
108  computeIK(q_des, q_dot_des, T_des, x_des, dt);
109 }
110 
111 void AMPlatePos5D::getStableAction(MatNd* action) const
112 {
113  // stable action == keeps current state
114  MatNd* x_curr;
115  MatNd_fromStack(x_curr, PLATE_TASK_DIM, 1);
116  // Compute current task state
117  getController()->computeX(x_curr);
118 
119  // copy parts of state relevant for the action
120  VecNd_copy(action->ele, x_curr->ele, 5);
121 }
122 
123 ActionModel* AMPlatePos5D::clone(RcsGraph* newGraph) const
124 {
125  auto res = new AMPlatePos5D(newGraph);
126  res->setupCollisionModel(collisionMdl);
127  return res;
128 }
129 
130 } /* namespace Rcs */
virtual void getStableAction(MatNd *action) const
virtual std::vector< std::string > getNames() const
AMPlatePos5D(RcsGraph *graph)
void addTask(Task *task)
RcsGraph * desiredGraph
virtual void computeCommand(MatNd *q_des, MatNd *q_dot_des, MatNd *T_des, const MatNd *action, double dt)
const unsigned int PLATE_TASK_DIM
virtual void getMinMax(double *min, double *max) const
virtual unsigned int getDim() const
void computeIK(MatNd *q_des, MatNd *q_dot_des, MatNd *T_des, const MatNd *x_des, double dt)
RcsCollisionMdl * collisionMdl
virtual ~AMPlatePos5D()
ActionModel * clone() const
Definition: ActionModel.h:72
const ControllerBase * getController() const
Definition: ActionModelIK.h:76