RcsPySim
A robot control and simulation library
ISSBallInTube.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 "ISSBallInTube.h"
32 
33 #include <Rcs_macros.h>
34 #include <Rcs_typedef.h>
35 
36 namespace Rcs
37 {
38 
39 ISSBallInTube::ISSBallInTube(RcsGraph* graph, bool fixedInitState) : InitStateSetter(graph), fixedInitState(fixedInitState)
40 {
41  // Grab direct references to the used bodies
42  platform = RcsGraph_getBodyByName(graph, "ImetronPlatform");
43  RCHECK(platform);
44  rail = RcsGraph_getBodyByName(graph, "RailBot");
45  RCHECK(rail);
46 }
47 
49 {
50  // Nothing to destroy
51 }
52 
53 unsigned int ISSBallInTube::getDim() const
54 {
55  return 4; // 3 base, 1 rail
56 }
57 
58 void ISSBallInTube::getMinMax(double* min, double* max) const
59 {
60  min[0] = -0.2; // base_x [m]
61  max[0] = +0.2;
62  min[1] = -0.05; // base_y [m]
63  max[1] = +0.05;
64  min[2] = RCS_DEG2RAD(-5.); // base_theta [rad]
65  max[2] = RCS_DEG2RAD(5.);
66  min[3] = 0.8; // rail_z [m]
67  max[3] = 0.9;
68 }
69 
70 std::vector<std::string> ISSBallInTube::getNames() const
71 {
72  return {"base_x", "base_y", "base_theta", "rail_z"};
73 }
74 
75 void ISSBallInTube::applyInitialState(const MatNd* initialState)
76 {
77  bool b0, b1, b2, b3;
78 
79  // Set the position to the box' rigid body joints directly in global world coordinates
80  if (fixedInitState) {
81  b0 = RcsGraph_setJoint(graph, "DofBaseX", -0.2);
82  b1 = RcsGraph_setJoint(graph, "DofBaseY", 0.);
83  b2 = RcsGraph_setJoint(graph, "DofBaseThZ", 0.);
84  b3 = RcsGraph_setJoint(graph, "DofChestZ", 0.85);
85  }
86  else {
87  b0 = RcsGraph_setJoint(graph, "DofBaseX", initialState->ele[0]);
88  b1 = RcsGraph_setJoint(graph, "DofBaseY", initialState->ele[1]);
89  b2 = RcsGraph_setJoint(graph, "DofBaseThZ", initialState->ele[2]);
90  b3 = RcsGraph_setJoint(graph, "DofChestZ", initialState->ele[3]);
91  }
92 
93  if (!(b0 && b1 && b2 && b3)) {
94  throw std::invalid_argument("Setting graph failed for at least one of the joints!");
95  }
96 
97  // Update the forward kinematics
98  RcsGraph_setState(graph, graph->q, graph->q_dot);
99 }
100 
101 } /* namespace Rcs */
ISSBallInTube(RcsGraph *graph, bool fixedInitState)
void getMinMax(double *min, double *max) const override
unsigned int getDim() const override
virtual ~ISSBallInTube()
virtual std::vector< std::string > getNames() const
void applyInitialState(const MatNd *initialState) override