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