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
30using namespace armarx;
31using namespace MotionControlGroup;
32
33// DO NOT EDIT NEXT LINE
34HardStopRobot::SubClassRegistry HardStopRobot::Registry(HardStopRobot::GetName(),
36
38 XMLStateTemplate<HardStopRobot>(stateData), HardStopRobotGeneratedBase<HardStopRobot>(stateData)
39{
40}
41
42void
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
123void
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
HardStopRobot(const XMLStateConstructorParams &stateData)
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
custom implementation of the StatechartContext for a statechart
Class for legacy to stay compatible with old statecharts.
Definition XMLState.h:147
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64