RcsPySim
A robot control and simulation library
ISSMiniGolf.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 "ISSMiniGolf.h"
32 
33 #include <Rcs_macros.h>
34 #include <Rcs_typedef.h>
35 
36 namespace Rcs
37 {
38 
39 ISSMiniGolf::ISSMiniGolf(RcsGraph* graph, bool fixedInitState) : InitStateSetter(graph), fixedInitState(fixedInitState)
40 {
41  // Grab direct references to the used bodies
42  ball = RcsGraph_getBodyByName(graph, "Ball");
43  RCHECK(ball);
44 }
45 
47 {
48  // Nothing to destroy
49 }
50 
51 unsigned int ISSMiniGolf::getDim() const
52 {
53  return 9; // ball x and y position + 7 joint angular positions
54 }
55 
56 void ISSMiniGolf::getMinMax(double* min, double* max) const
57 {
58  double ballPosHalfSpanX = 1e-6; // [m]
59  double ballPosHalfSpanY = 1e-2; // [m]
60  double jointAngHalfSpan = 1e-6; // [rad]
61 
62  min[0] = 0.304096 - ballPosHalfSpanX; // ball_x [m]
63  max[0] = 0.304096 + ballPosHalfSpanX;
64  min[1] = 1.29785 - ballPosHalfSpanY; // ball_y [m]
65  max[1] = 1.29785 + ballPosHalfSpanY;
66  min[2] = RCS_DEG2RAD(18.996253 - jointAngHalfSpan); // base-m3 [rad]
67  max[2] = RCS_DEG2RAD(18.996253 + jointAngHalfSpan);
68  min[3] = RCS_DEG2RAD(-87.227101 - jointAngHalfSpan); // m3-m4 [rad]
69  max[3] = RCS_DEG2RAD(-87.227101 + jointAngHalfSpan);
70  min[4] = RCS_DEG2RAD(74.149568 - jointAngHalfSpan); // m4-m5 [rad]
71  max[4] = RCS_DEG2RAD(74.149568 + jointAngHalfSpan);
72  min[5] = RCS_DEG2RAD(-75.577025 - jointAngHalfSpan); // m5-m6 [rad]
73  max[5] = RCS_DEG2RAD(-75.577025 + jointAngHalfSpan);
74  min[6] = RCS_DEG2RAD(56.207369 - jointAngHalfSpan); // m6-m7 [rad]
75  max[6] = RCS_DEG2RAD(56.207369 + jointAngHalfSpan);
76  min[7] = RCS_DEG2RAD(-175.162794 - jointAngHalfSpan); // m7-m8 [rad]
77  max[7] = RCS_DEG2RAD(-175.162794 + jointAngHalfSpan);
78  min[8] = RCS_DEG2RAD(-41.543793 - jointAngHalfSpan); // m8-m9 [rad]
79  max[8] = RCS_DEG2RAD(-41.543793 + jointAngHalfSpan);
80 }
81 
82 std::vector<std::string> ISSMiniGolf::getNames() const
83 {
84  return {"ball_x", "ball_y", "base-m3", "m3-m4", "m4-m5", "m5-m6", "m6-m7", "m7-m8", "m8-m9"};
85 }
86 
87 void ISSMiniGolf::applyInitialState(const MatNd* initialState)
88 {
89  // Set the position to the box' rigid body joints directly in global world coordinates
90  double* ballRBJ = &graph->q->ele[ball->jnt->jointIndex];
91  if (fixedInitState) {
92  ballRBJ[0] = 0.304096; // ball_x [m]
93  ballRBJ[1] = 1.29785; // ball_y [m]
94  RcsGraph_setJoint(graph, "base-m3", RCS_DEG2RAD(18.996253));
95  RcsGraph_setJoint(graph, "m3-m4", RCS_DEG2RAD(-87.227101));
96  RcsGraph_setJoint(graph, "m4-m5", RCS_DEG2RAD(74.149568));
97  RcsGraph_setJoint(graph, "m5-m6", RCS_DEG2RAD(-75.577025));
98  RcsGraph_setJoint(graph, "m6-m7", RCS_DEG2RAD(56.207369));
99  RcsGraph_setJoint(graph, "m7-m8", RCS_DEG2RAD(-175.162794));
100  RcsGraph_setJoint(graph, "m8-m9", RCS_DEG2RAD(-41.543793));
101  }
102  else {
103  ballRBJ[0] = initialState->ele[0];
104  ballRBJ[1] = initialState->ele[1];
105  RcsGraph_setJoint(graph, "base-m3", initialState->ele[2]);
106  RcsGraph_setJoint(graph, "m3-m4", initialState->ele[3]);
107  RcsGraph_setJoint(graph, "m4-m5", initialState->ele[4]);
108  RcsGraph_setJoint(graph, "m5-m6", initialState->ele[5]);
109  RcsGraph_setJoint(graph, "m6-m7", initialState->ele[6]);
110  RcsGraph_setJoint(graph, "m7-m8", initialState->ele[7]);
111  RcsGraph_setJoint(graph, "m8-m9", initialState->ele[8]);
112  }
113 
114  // Update the forward kinematics
115  RcsGraph_setState(graph, graph->q, graph->q_dot);
116 }
117 
118 } /* namespace Rcs */
RcsBody * ball
Definition: ISSMiniGolf.h:65
void getMinMax(double *min, double *max) const override
Definition: ISSMiniGolf.cpp:56
void applyInitialState(const MatNd *initialState) override
Definition: ISSMiniGolf.cpp:87
virtual ~ISSMiniGolf()
Definition: ISSMiniGolf.cpp:46
ISSMiniGolf(RcsGraph *graph, bool fixedInitState)
Definition: ISSMiniGolf.cpp:39
unsigned int getDim() const override
Definition: ISSMiniGolf.cpp:51
virtual std::vector< std::string > getNames() const
Definition: ISSMiniGolf.cpp:82