MoveTableImpedanceControl.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::MoveTableImpedanceControlGroup
19 * @author [Author Name] ( [Author Email] )
20 * @date 2014
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
26#include <VirtualRobot/MathTools.h>
27
29
30
31using namespace armarx;
32using namespace CoupledInteractionGroup;
33
34// DO NOT EDIT NEXT LINE
35MoveTableImpedanceControl::SubClassRegistry
38
44
45void
47{
49 getContext<CoupledInteractionGroupStatechartContext>();
50
51
52 Eigen::Vector3f zeroVelVec;
53 zeroVelVec << 0.0, 0.0, 0.0;
54 std::string leftTcpName = in.getLeftHandName();
55 std::string rightTcpName = in.getRightHandName();
56 //leftTcpName = std::string("Wrist 2 L");
57 //rightTcpName = std::string("Wrist 2 R");
58 //std::string leftTcpName("Wrist 2 L");
59 //std::string rightTcpName("Wrist 2 R");
60 DatafieldRefPtr forceRefLeft = DatafieldRefPtr::dynamicCast(
61 context->getForceTorqueUnitObserver()->getForceDatafield(leftTcpName));
62 DatafieldRefPtr torqueRefLeft = DatafieldRefPtr::dynamicCast(
63 context->getForceTorqueUnitObserver()->getTorqueDatafield(leftTcpName));
64 DatafieldRefPtr forceRefRight = DatafieldRefPtr::dynamicCast(
65 context->getForceTorqueUnitObserver()->getForceDatafield(rightTcpName));
66 DatafieldRefPtr torqueRefRight = DatafieldRefPtr::dynamicCast(
67 context->getForceTorqueUnitObserver()->getTorqueDatafield(rightTcpName));
68 forceRefLeft = DatafieldRefPtr::dynamicCast(
69 context->getForceTorqueUnitObserver()->createNulledDatafield(forceRefLeft));
70 forceRefRight = DatafieldRefPtr::dynamicCast(
71 context->getForceTorqueUnitObserver()->createNulledDatafield(forceRefRight));
72 torqueRefLeft = DatafieldRefPtr::dynamicCast(
73 context->getForceTorqueUnitObserver()->createNulledDatafield(torqueRefLeft));
74 torqueRefRight = DatafieldRefPtr::dynamicCast(
75 context->getForceTorqueUnitObserver()->createNulledDatafield(torqueRefRight));
76 FramedDirectionPtr curForceLeft = forceRefLeft->getDataField()->get<FramedDirection>();
77 curForceLeft = FramedDirection::ChangeFrame(context->getRobot(), *curForceLeft, "Armar3_Base");
78 FramedDirectionPtr curForceRight = forceRefRight->getDataField()->get<FramedDirection>();
79 curForceRight =
80 FramedDirection::ChangeFrame(context->getRobot(), *curForceRight, "Armar3_Base");
81 FramedDirectionPtr curTorqueLeft = torqueRefLeft->getDataField()->get<FramedDirection>();
82 curTorqueLeft =
83 FramedDirection::ChangeFrame(context->getRobot(), *curTorqueLeft, "Armar3_Base");
84 FramedDirectionPtr curTorqueRight = torqueRefRight->getDataField()->get<FramedDirection>();
85 curTorqueRight =
86 FramedDirection::ChangeFrame(context->getRobot(), *curTorqueRight, "Armar3_Base");
87 Eigen::Matrix4f leftTcpPoseBase =
88 context->getRobot()->getRobotNode(in.getLeftHandName())->getPoseInRootFrame();
89 Eigen::Matrix4f rightTcpPoseBase =
90 context->getRobot()->getRobotNode(in.getRightHandName())->getPoseInRootFrame();
91
92 Eigen::Vector3f desiredLeftRPY;
93 VirtualRobot::MathTools::eigen4f2rpy(leftTcpPoseBase, desiredLeftRPY);
94 Eigen::Vector3f desiredRightRPY;
95 VirtualRobot::MathTools::eigen4f2rpy(rightTcpPoseBase, desiredRightRPY);
96 local.setDesiredLeftTcpPose(FramedPose(leftTcpPoseBase, "Armar3_Base", "Armar3"));
97 local.setDesiredRightTcpPose(FramedPose(rightTcpPoseBase, "Armar3_Base", "Armar3"));
98 local.setDesiredLeftTcpOrientation(FramedDirection(desiredLeftRPY, "Armar3_Base", "Armar3"));
99 local.setDesiredRightTcpOrientation(FramedDirection(desiredRightRPY, "Armar3_Base", "Armar3"));
100 local.setCurrentLeftTcpOriVelocity(FramedDirection(zeroVelVec, "Armar3_Base", "Armar3"));
101 local.setCurrentLeftTcpPosVelocity(FramedDirection(zeroVelVec, "Armar3_Base", "Armar3"));
102 local.setCurrentRightTcpOriVelocity(FramedDirection(zeroVelVec, "Armar3_Base", "Armar3"));
103 local.setCurrentRightTcpPosVelocity(FramedDirection(zeroVelVec, "Armar3_Base", "Armar3"));
104 local.setCurrentPlatformVelocity(Vector3(zeroVelVec));
105 local.setTimestamp(TimestampVariant::nowPtr());
106 local.setinitialForcesReset(true);
107 local.setcounter(0);
108 int timeout = in.getTimeout();
109
110 if (timeout > 0)
111 {
112 setTimeoutEvent(timeout, createEventTimeout());
113 }
114}
115
116void
118{
120 getContext<CoupledInteractionGroupStatechartContext>();
121 //std::string leftTcpName("Wrist 2 L");
122 //std::string rightTcpName("Wrist 2 R");
123 std::string leftTcpName = in.getLeftHandName();
124 std::string rightTcpName = in.getRightHandName();
125 DatafieldRefPtr forceRefLeft = DatafieldRefPtr::dynamicCast(
126 context->getForceTorqueUnitObserver()->getForceDatafield(leftTcpName));
127 DatafieldRefPtr torqueRefLeft = DatafieldRefPtr::dynamicCast(
128 context->getForceTorqueUnitObserver()->getTorqueDatafield(leftTcpName));
129 DatafieldRefPtr forceRefRight = DatafieldRefPtr::dynamicCast(
130 context->getForceTorqueUnitObserver()->getForceDatafield(rightTcpName));
131 DatafieldRefPtr torqueRefRight = DatafieldRefPtr::dynamicCast(
132 context->getForceTorqueUnitObserver()->getTorqueDatafield(rightTcpName));
133 context->getForceTorqueUnitObserver()->removeFilteredDatafield(forceRefLeft);
134 context->getForceTorqueUnitObserver()->removeFilteredDatafield(forceRefRight);
135 context->getForceTorqueUnitObserver()->removeFilteredDatafield(torqueRefLeft);
136 context->getForceTorqueUnitObserver()->removeFilteredDatafield(torqueRefRight);
137
138 // put your user code for the exit point here
139 // execution time should be short (<100ms)
140}
141
142// DO NOT EDIT NEXT FUNCTION
143std::string
145{
146 return "MoveTableImpedanceControl";
147}
148
149// DO NOT EDIT NEXT FUNCTION
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
FramedDirection is a 3 dimensional direction vector with a reference frame.
Definition FramedPose.h:87
static FramedDirectionPtr ChangeFrame(const VirtualRobot::RobotConstPtr &robot, const FramedDirection &framedVec, const std::string &newFrame)
The FramedPose class.
Definition FramedPose.h:281
static TimestampVariantPtr nowPtr()
The Vector3 class.
Definition Pose.h:113
Class for legacy to stay compatible with old statecharts.
Definition XMLState.h:147
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< FramedDirection > FramedDirectionPtr
Definition FramedPose.h:84
IceInternal::Handle< DatafieldRef > DatafieldRefPtr
Definition Observer.h:43
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64