RcsPySim
A robot control and simulation library
ISSBoxLifting.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 "ISSBoxLifting.h"
32 
33 #include <Rcs_macros.h>
34 #include <Rcs_typedef.h>
35 
36 namespace Rcs
37 {
38 
39 ISSBoxLifting::ISSBoxLifting(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  link2R = RcsGraph_getBodyByName(graph, "lbr_link_2_R");
48  RCHECK(link2R);
49  box = RcsGraph_getBodyByName(graph, "Box");
50  RCHECK(box);
51 }
52 
54 {
55  // Nothing to destroy
56 }
57 
58 unsigned int ISSBoxLifting::getDim() const
59 {
60  return 6; // 3 base, 1 rail, 1 LBR joints, 1 box
61 }
62 
63 void ISSBoxLifting::getMinMax(double* min, double* max) const
64 {
65  min[0] = 0.05; // base_x [m]
66  max[0] = 0.25;
67  min[1] = -0.05; // base_y [m]
68  max[1] = 0.05;
69  min[3] = 0.8; // rail_z [m]
70  max[3] = 0.9;
71  min[4] = RCS_DEG2RAD(-70.); // joint_2_R [rad]
72  max[4] = RCS_DEG2RAD(-60.);
73  min[5] = -0.04; // box_y [m]
74  max[5] = 0.04;
75 }
76 
77 std::vector<std::string> ISSBoxLifting::getNames() const
78 {
79  return {"base_x", "base_y", "base_theta", "rail_z", "joint_2_R", "box_y"};
80 }
81 
82 void ISSBoxLifting::applyInitialState(const MatNd* initialState)
83 {
84 // bool b0, b1, b2, b3;
85  bool b4;
86 
87  // Set the position to the box' rigid body joints directly in global world coordinates
88  if (fixedInitState) {
89 // b0 = RcsGraph_setJoint(graph, "DofBaseX", 0.2);
90 // b1 = RcsGraph_setJoint(graph, "DofBaseY", 0.);
91 // b2 = RcsGraph_setJoint(graph, "DofBaseThZ", 0.);
92 // b3 = RcsGraph_setJoint(graph, "DofChestZ", 0.85);
93  b4 = RcsGraph_setJoint(graph, "lbr_joint_2_R", RCS_DEG2RAD(-65.));
94  graph->q->ele[box->jnt->jointIndex + 1] = initialState->ele[5];
95  }
96  else {
97 // b0 = RcsGraph_setJoint(graph, "DofBaseX", initialState->ele[0]);
98 // b1 = RcsGraph_setJoint(graph, "DofBaseY", initialState->ele[1]);
99 // b2 = RcsGraph_setJoint(graph, "DofBaseThZ", initialState->ele[2]);
100 // b3 = RcsGraph_setJoint(graph, "DofChestZ", initialState->ele[3]);
101  b4 = RcsGraph_setJoint(graph, "lbr_joint_2_R", initialState->ele[4]);
102  graph->q->ele[box->jnt->jointIndex + 1] = initialState->ele[5];
103  }
104 
105  if (!(b4)) {
106  throw std::invalid_argument("Setting graph failed for at least one of the joints!");
107  }
108 
109  // Update the forward kinematics
110  RcsGraph_setState(graph, graph->q, graph->q_dot);
111 }
112 
113 } /* namespace Rcs */
void getMinMax(double *min, double *max) const override
virtual std::vector< std::string > getNames() const
ISSBoxLifting(RcsGraph *graph, bool fixedInitState)
void applyInitialState(const MatNd *initialState) override
virtual ~ISSBoxLifting()
unsigned int getDim() const override