RcsPySim
A robot control and simulation library
AMJointControlPosition.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 "AMJointControlPosition.h"
32 
33 #include <Rcs_typedef.h>
34 #include <Rcs_macros.h>
35 
36 #include <iostream>
37 
38 namespace Rcs
39 {
40 
41 
43 {
44  // Make sure nJ is correct
45  RcsGraph_setState(graph, NULL, NULL);
46  // Iterate over unconstrained joints
47  REXEC(1) {
48  RCSGRAPH_TRAVERSE_JOINTS(graph) {
49  if (JNT->jacobiIndex != -1) {
50  // Check if the joints actually use position control inside the simulation
51  if (JNT->ctrlType != RCSJOINT_CTRL_POSITION) {
52  std::cout
53  << "Using AMJointControlPosition, but at least one joint does not have the control type "
54  "RCSJOINT_CTRL_POSITION!" << std::endl;
55  }
56  }
57  }
58  }
59 }
60 
62 {
63  // Nothing to destroy
64 }
65 
66 void
67 AMJointControlPosition::computeCommand(MatNd* q_des, MatNd* q_dot_des, MatNd* T_des, const MatNd* action, double dt)
68 {
69  RcsGraph_stateVectorFromIK(graph, action, q_des);
70 }
71 
72 void AMJointControlPosition::getMinMax(double* min, double* max) const
73 {
74  RCSGRAPH_TRAVERSE_JOINTS(graph) {
75  if (JNT->jacobiIndex != -1) {
76  // Set min/max from joint limits
77  min[JNT->jacobiIndex] = JNT->q_min;
78  max[JNT->jacobiIndex] = JNT->q_max;
79  }
80  }
81 }
82 
83 void AMJointControlPosition::getStableAction(MatNd* action) const
84 {
85  // Stable action = current state
86  RcsGraph_stateVectorToIK(graph, graph->q, action);
87 }
88 
89 std::vector<std::string> AMJointControlPosition::getNames() const
90 {
91  std::vector<std::string> out;
92  RCSGRAPH_TRAVERSE_JOINTS(graph) {
93  if (JNT->jacobiIndex != -1) {
94  out.emplace_back(JNT->name);
95  }
96  }
97 
98  return out;
99 }
100 
101 ActionModel* AMJointControlPosition::clone(RcsGraph* newGraph) const
102 {
103  return new AMJointControlPosition(newGraph);
104 }
105 
106 } /* namespace Rcs */
107 
virtual void getStableAction(MatNd *action) const
virtual std::vector< std::string > getNames() const
ActionModel * clone() const
Definition: ActionModel.h:72
RcsGraph * graph
Definition: ActionModel.h:194
virtual void computeCommand(MatNd *q_des, MatNd *q_dot_des, MatNd *T_des, const MatNd *action, double dt)
virtual void getMinMax(double *min, double *max) const