RcsPySim
A robot control and simulation library
PPDBodyOrientation.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 "PPDBodyOrientation.h"
32 #include "PPDSingleVar.h"
33 
34 #include <Rcs_typedef.h>
35 #include <Rcs_Mat3d.h>
36 #include <Rcs_Vec3d.h>
37 
38 #include <stdexcept>
39 
40 namespace Rcs
41 {
42 
43 void Vec33d_setZero(double v[3][3])
44 {
45  for (unsigned int i = 0; i < 3; i++) {
46  for (unsigned int j = 0; j < 3; j++) {
47  v[i][j] = 0.0;
48  }
49  }
50 }
51 
52 void Vec33d_add(double dst[3][3], const double v1[3][3], const double v2[3][3])
53 {
54  for (unsigned int i = 0; i < 3; i++) {
55  for (unsigned int j = 0; j < 3; j++) {
56  dst[i][j] = v1[i][j] + v2[i][j];
57  }
58  }
59 }
60 
61 PPDBodyOrientation::PPDBodyOrientation(const bool includeA, const bool includeB, const bool includeC)
62 {
63  Vec33d_setZero(initRot); // undefined
64  Vec3d_setZero(offsetRot);
65 
66  if (includeA) {
68  "rot_offset_a", BodyParamInfo::MOD_ORIENTATION,
69  [this](BodyParamInfo& bpi) -> double& { return (offsetRot[0]); })
70  );
71  }
72  if (includeB) {
74  "rot_offset_b", BodyParamInfo::MOD_ORIENTATION,
75  [this](BodyParamInfo& bpi) -> double& { return (offsetRot[1]); })
76  );
77  }
78  if (includeC) {
80  "rot_offset_c", BodyParamInfo::MOD_ORIENTATION,
81  [this](BodyParamInfo& bpi) -> double& { return (offsetRot[2]); })
82  );
83  }
84 
85  if (getChildren().empty()) {
86  throw std::invalid_argument("No position specified for PPDBodyOrientation!");
87  }
88 }
89 
91 
93 {
94  PPDCompound::init(bpi);
95 
96  // Copy the rotation about the world x, y, and z axis. Here, a special case of MatNd_copy().
97  memmove(initRot, bpi->body->A_BP->rot, 3*3*sizeof(double));
98 }
99 
101 {
102  PPDCompound::setValues(inValues);
103 
104  // Copy the rotation about the world x, y, and z axis. Here, a special case of MatNd_copy().
105  double tmpRot[3][3];
106  memmove(tmpRot, initRot, 3*3*sizeof(double));
107 
108  // Apply the orientation to the body. The default value for offsetRot is zero.
109  Mat3d_rotateSelfAboutXYZAxis(tmpRot, 0, offsetRot[0]);
110  Mat3d_rotateSelfAboutXYZAxis(tmpRot, 1, offsetRot[1]);
111  Mat3d_rotateSelfAboutXYZAxis(tmpRot, 2, offsetRot[2]);
112 
113  // Copy the rotation about the world x, y, and z axis. Here, a special case of MatNd_copy().
114  memmove(this->bodyParamInfo->body->A_BP->rot, tmpRot, 3*3*sizeof(double));
115 }
116 
117 } /* namespace Rcs */
void addChild(PhysicsParameterDescriptor *)
Definition: PPDCompound.cpp:59
RcsBody * body
The body.
Definition: BodyParamInfo.h:64
const std::vector< PhysicsParameterDescriptor * > & getChildren() const
Definition: PPDCompound.cpp:72
virtual void init(BodyParamInfo *bodyParamInfo)
Definition: PPDCompound.cpp:64
void Vec33d_add(double dst[3][3], const double v1[3][3], const double v2[3][3])
virtual void setValues(PropertySource *inValues)
Definition: PPDCompound.cpp:52
PPDBodyOrientation(bool includeA, bool includeB, bool includeC)
virtual void init(BodyParamInfo *bpi)
void Vec33d_setZero(double v[3][3])
double offsetRot[3]
Angular (around the elementary axes) offset values.
virtual void setValues(PropertySource *inValues)
double initRot[3][3]
The body&#39;s nominal orientation (in world coordinates / the parent&#39;s coordinates)