HardStopRobot.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2014-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package RobotSkillTemplates::MotionControlGroup
19  * @author Mirko Waechter ( waechter at kit dot edu )
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #include "HardStopRobot.h"
27 
28 using namespace armarx;
29 using namespace MotionControlGroup;
30 
31 // DO NOT EDIT NEXT LINE
32 HardStopRobot::SubClassRegistry HardStopRobot::Registry(HardStopRobot::GetName(), &HardStopRobot::CreateInstance);
33 
34 
35 
37  XMLStateTemplate<HardStopRobot>(stateData), HardStopRobotGeneratedBase<HardStopRobot>(stateData)
38 {
39 }
40 
42 {
43  // put your user code for the enter-point here
44  // execution time should be short (<100ms)
45 
46  MotionControlGroupStatechartContext* context = getContext<MotionControlGroupStatechartContext>();
47 
48  std::string kinematicChain = "";
49 
50  if (in.isKinematicChainNameSet())
51  {
52  kinematicChain = in.getKinematicChainName();
53  }
54 
55 
56 
57  Ice::StringSeq nodeNames;
58 
59  if (kinematicChain.empty())
60  {
61  auto start = IceUtil::Time::now();
62  nodeNames = context->getRobot()->getSharedRobot()->getRobotNodes();
63  ARMARX_INFO << "getting nodes took " << (IceUtil::Time::now() - start).toMilliSecondsDouble() << "ms";
64  }
65  else
66  {
67  VirtualRobot::RobotNodeSetPtr nodeSet = context->getRobot()->getRobotNodeSet(kinematicChain);
68 
69  for (size_t i = 0; i < nodeSet->getSize(); ++i)
70  {
71  nodeNames.push_back(nodeSet->getNode(i)->getName());
72  }
73  }
74 
75  ARMARX_INFO << "Stopping joints, kin chain:" << kinematicChain << ", nodes:" << nodeNames;
76 
77 
78 
79 
80 
81  NameValueMap zeroJointVelocities;
82  NameControlModeMap modes;
83 
84  for (auto& name : nodeNames)
85  {
86  zeroJointVelocities[name] = 0.0f;
87  modes[name] = eVelocityControl;
88  }
89 
90  auto start = IceUtil::Time::now();
91 
92  context->getKinematicUnit()->setJointVelocities(zeroJointVelocities);
93  context->getKinematicUnit()->switchControlMode(modes);
94  ARMARX_INFO << "setting joint velos took " << (IceUtil::Time::now() - start).toMilliSecondsDouble() << "ms";
95  start = IceUtil::Time::now();
96 
97  NameValueMap jointMap = context->getRobot()->getSharedRobot()->getConfig();
98  ARMARX_INFO << "getting robot config took " << (IceUtil::Time::now() - start).toMilliSecondsDouble() << "ms";
99  NameValueMap jointPositions;
100  modes.clear();
101 
102  for (auto& name : nodeNames)
103  {
104  auto it = jointMap.find(name);
105 
106  if (it != jointMap.end())
107  {
108  jointPositions[name] = it->second;
109  modes[name] = ePositionControl;
110  }
111  }
112 
113  ARMARX_INFO << "new joint angles: " << jointPositions;
114  context->getKinematicUnit()->setJointAngles(jointPositions);
115  context->getKinematicUnit()->switchControlMode(modes);
116 
117  emitStopped();
118 
119 }
120 
121 
122 
124 {
125  // put your user code for the exit point here
126  // execution time should be short (<100ms)
127 
128 }
129 
130 
131 // DO NOT EDIT NEXT FUNCTION
133 {
134  return XMLStateFactoryBasePtr(new HardStopRobot(stateData));
135 }
136 
armarx::MotionControlGroup::HardStopRobot
Definition: HardStopRobot.h:31
armarx::MotionControlGroup::MotionControlGroupStatechartContext
Definition: MotionControlGroupStatechartContext.h:66
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::navigation::platform_controller::platform_global_trajectory::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformGlobalTrajectoryController.h:93
HardStopRobot.h
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::MotionControlGroup::MotionControlGroupStatechartContext::getRobot
const std::shared_ptr< RemoteRobot > getRobot()
Definition: MotionControlGroupStatechartContext.h:79
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:137
armarx::MotionControlGroup::HardStopRobot::onExit
void onExit() override
Definition: HardStopRobot.cpp:123
MotionControlGroupStatechartContext.h
armarx::MotionControlGroup::HardStopRobot::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: HardStopRobot.cpp:132
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
armarx::MotionControlGroup::MotionControlGroupStatechartContext::getKinematicUnit
KinematicUnitInterfacePrx getKinematicUnit()
Definition: MotionControlGroupStatechartContext.h:100
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::MotionControlGroup::HardStopRobot::Registry
static SubClassRegistry Registry
Definition: HardStopRobot.h:43
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::MotionControlGroup::HardStopRobot::onEnter
void onEnter() override
Definition: HardStopRobot.cpp:41
armarx::MotionControlGroup::HardStopRobot::HardStopRobot
HardStopRobot(const XMLStateConstructorParams &stateData)
Definition: HardStopRobot.cpp:36