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"
26 #include <VirtualRobot/RobotNodeSet.h>
27 
29 
30 using namespace armarx;
31 using namespace MotionControlGroup;
32 
33 // DO NOT EDIT NEXT LINE
34 HardStopRobot::SubClassRegistry HardStopRobot::Registry(HardStopRobot::GetName(),
36 
38  XMLStateTemplate<HardStopRobot>(stateData), HardStopRobotGeneratedBase<HardStopRobot>(stateData)
39 {
40 }
41 
42 void
44 {
45  // put your user code for the enter-point here
46  // execution time should be short (<100ms)
47 
49  getContext<MotionControlGroupStatechartContext>();
50 
51  std::string kinematicChain = "";
52 
53  if (in.isKinematicChainNameSet())
54  {
55  kinematicChain = in.getKinematicChainName();
56  }
57 
58 
59  Ice::StringSeq nodeNames;
60 
61  if (kinematicChain.empty())
62  {
63  auto start = IceUtil::Time::now();
64  nodeNames = context->getRobot()->getSharedRobot()->getRobotNodes();
65  ARMARX_INFO << "getting nodes took "
66  << (IceUtil::Time::now() - start).toMilliSecondsDouble() << "ms";
67  }
68  else
69  {
70  VirtualRobot::RobotNodeSetPtr nodeSet =
71  context->getRobot()->getRobotNodeSet(kinematicChain);
72 
73  for (size_t i = 0; i < nodeSet->getSize(); ++i)
74  {
75  nodeNames.push_back(nodeSet->getNode(i)->getName());
76  }
77  }
78 
79  ARMARX_INFO << "Stopping joints, kin chain:" << kinematicChain << ", nodes:" << nodeNames;
80 
81 
82  NameValueMap zeroJointVelocities;
83  NameControlModeMap modes;
84 
85  for (auto& name : nodeNames)
86  {
87  zeroJointVelocities[name] = 0.0f;
88  modes[name] = eVelocityControl;
89  }
90 
91  auto start = IceUtil::Time::now();
92 
93  context->getKinematicUnit()->setJointVelocities(zeroJointVelocities);
94  context->getKinematicUnit()->switchControlMode(modes);
95  ARMARX_INFO << "setting joint velos took "
96  << (IceUtil::Time::now() - start).toMilliSecondsDouble() << "ms";
97  start = IceUtil::Time::now();
98 
99  NameValueMap jointMap = context->getRobot()->getSharedRobot()->getConfig();
100  ARMARX_INFO << "getting robot config took "
101  << (IceUtil::Time::now() - start).toMilliSecondsDouble() << "ms";
102  NameValueMap jointPositions;
103  modes.clear();
104 
105  for (auto& name : nodeNames)
106  {
107  auto it = jointMap.find(name);
108 
109  if (it != jointMap.end())
110  {
111  jointPositions[name] = it->second;
112  modes[name] = ePositionControl;
113  }
114  }
115 
116  ARMARX_INFO << "new joint angles: " << jointPositions;
117  context->getKinematicUnit()->setJointAngles(jointPositions);
118  context->getKinematicUnit()->switchControlMode(modes);
119 
120  emitStopped();
121 }
122 
123 void
125 {
126  // put your user code for the exit point here
127  // execution time should be short (<100ms)
128 }
129 
130 // DO NOT EDIT NEXT FUNCTION
133 {
134  return XMLStateFactoryBasePtr(new HardStopRobot(stateData));
135 }
armarx::MotionControlGroup::HardStopRobot
Definition: HardStopRobot.h:31
armarx::MotionControlGroup::MotionControlGroupStatechartContext
Definition: MotionControlGroupStatechartContext.h:75
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
HardStopRobot.h
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::MotionControlGroup::MotionControlGroupStatechartContext::getRobot
const std::shared_ptr< RemoteRobot > getRobot()
Definition: MotionControlGroupStatechartContext.h:90
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:146
armarx::MotionControlGroup::HardStopRobot::onExit
void onExit() override
Definition: HardStopRobot.cpp:124
MotionControlGroupStatechartContext.h
armarx::MotionControlGroup::HardStopRobot::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: HardStopRobot.cpp:132
armarx::control::njoint_controller::platform::platform_follower_controller::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformFollowerController.h:88
armarx::MotionControlGroup::MotionControlGroupStatechartContext::getKinematicUnit
KinematicUnitInterfacePrx getKinematicUnit()
Definition: MotionControlGroupStatechartContext.h:120
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::MotionControlGroup::HardStopRobot::Registry
static SubClassRegistry Registry
Definition: HardStopRobot.h:42
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::MotionControlGroup::HardStopRobot::onEnter
void onEnter() override
Definition: HardStopRobot.cpp:43
armarx::MotionControlGroup::HardStopRobot::HardStopRobot
HardStopRobot(const XMLStateConstructorParams &stateData)
Definition: HardStopRobot.cpp:37