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 
31 using namespace armarx;
32 using namespace CoupledInteractionGroup;
33 
34 // DO NOT EDIT NEXT LINE
35 MoveTableImpedanceControl::SubClassRegistry
38 
41  MoveTableImpedanceControlGeneratedBase<MoveTableImpedanceControl>(stateData)
42 {
43 }
44 
45 void
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 
116 void
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
143 std::string
145 {
146  return "MoveTableImpedanceControl";
147 }
148 
149 // DO NOT EDIT NEXT FUNCTION
152 {
153  return XMLStateFactoryBasePtr(new MoveTableImpedanceControl(stateData));
154 }
RemoteRobot.h
armarx::VariantType::FramedPose
const VariantTypeId FramedPose
Definition: FramedPose.h:36
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getForceTorqueUnitObserver
ForceTorqueUnitObserverInterfacePrx getForceTorqueUnitObserver()
Definition: CoupledInteractionGroupStatechartContext.h:221
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
armarx::CoupledInteractionGroup::MoveTableImpedanceControl
Definition: MoveTableImpedanceControl.h:37
armarx::CoupledInteractionGroup::MoveTableImpedanceControl::GetName
static std::string GetName()
Definition: MoveTableImpedanceControl.cpp:144
armarx::TimestampVariant::nowPtr
static TimestampVariantPtr nowPtr()
Definition: TimestampVariant.h:126
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
armarx::CoupledInteractionGroup::MoveTableImpedanceControl::onExit
void onExit() override
Definition: MoveTableImpedanceControl.cpp:117
armarx::CoupledInteractionGroup::MoveTableImpedanceControl::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: MoveTableImpedanceControl.cpp:151
IceInternal::Handle< DatafieldRef >
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getRobot
const VirtualRobot::RobotPtr getRobot()
Definition: CoupledInteractionGroupStatechartContext.h:133
armarx::CoupledInteractionGroup::MoveTableImpedanceControl::onEnter
void onEnter() override
Definition: MoveTableImpedanceControl.cpp:46
armarx::FramedDirection::ChangeFrame
static FramedDirectionPtr ChangeFrame(const VirtualRobot::RobotPtr &robot, const FramedDirection &framedVec, const std::string &newFrame)
Definition: FramedPose.cpp:91
MoveTableImpedanceControl.h
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:146
armarx::CoupledInteractionGroup::MoveTableImpedanceControl::MoveTableImpedanceControl
MoveTableImpedanceControl(XMLStateConstructorParams stateData)
Definition: MoveTableImpedanceControl.cpp:39
armarx::FramedDirection
FramedDirection is a 3 dimensional direction vector with a reference frame. The reference frame can b...
Definition: FramedPose.h:86
armarx::VariantType::FramedDirection
const VariantTypeId FramedDirection
Definition: FramedPose.h:37
memoryx::KBM::Vector3
Eigen::Vector3d Vector3
Definition: kbm.h:43
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext
Definition: CoupledInteractionGroupStatechartContext.h:118
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::CoupledInteractionGroup::MoveTableImpedanceControl::Registry
static SubClassRegistry Registry
Definition: MoveTableImpedanceControl.h:50