PlaceTable.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::PlaceTableGroup
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 
25 #include "PlaceTable.h"
26 
28 
29 
30 using namespace armarx;
31 using namespace CoupledInteractionGroup;
32 
33 // DO NOT EDIT NEXT LINE
34 PlaceTable::SubClassRegistry PlaceTable::Registry(PlaceTable::GetName(),
36 
38  XMLStateTemplate<PlaceTable>(stateData), PlaceTableGeneratedBase<PlaceTable>(stateData)
39 {
40 }
41 
42 void
44 {
46  getContext<CoupledInteractionGroupStatechartContext>();
47  context->getTCPControlUnit()->request();
48 
49  // put your user code for the enter-point here
50  // execution time should be short (<100ms)
51  //std::string leftTcpName("Wrist 2 L");
52  //std::string rightTcpName("Wrist 2 R");
53  std::string leftTcpName = in.getLeftHandName();
54  std::string rightTcpName = in.getRightHandName();
55  //leftTcpName = std::string("Wrist 2 L");
56  //rightTcpName = std::string("Wrist 2 R");
57  //else
58  // duration = IceUtil::Time::milliSecondsDouble(0);
59 
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 
77  FramedDirectionPtr curForceLeft = forceRefLeft->getDataField()->get<FramedDirection>();
78  curForceLeft = FramedDirection::ChangeFrame(context->getRobot(), *curForceLeft, "Armar3_Base");
79  FramedDirectionPtr curForceRight = forceRefRight->getDataField()->get<FramedDirection>();
80  curForceRight =
81  FramedDirection::ChangeFrame(context->getRobot(), *curForceRight, "Armar3_Base");
82  FramedDirectionPtr curTorqueLeft = torqueRefLeft->getDataField()->get<FramedDirection>();
83  curTorqueLeft =
84  FramedDirection::ChangeFrame(context->getRobot(), *curTorqueLeft, "Armar3_Base");
85  FramedDirectionPtr curTorqueRight = torqueRefRight->getDataField()->get<FramedDirection>();
86  curTorqueRight =
87  FramedDirection::ChangeFrame(context->getRobot(), *curTorqueRight, "Armar3_Base");
88  Eigen::Vector3f zeroVelVec;
89  zeroVelVec << 0.0, 0.0, 0.0;
90  FramedDirectionPtr curVelLeft = new FramedDirection(zeroVelVec, "Armar3_Base", "Armar3");
91  FramedDirectionPtr curVelRight = new FramedDirection(zeroVelVec, "Armar3_Base", "Armar3");
92  FramedDirectionPtr curVelOriLeft = new FramedDirection(zeroVelVec, "Armar3_Base", "Armar3");
93  FramedDirectionPtr curVelOriRight = new FramedDirection(zeroVelVec, "Armar3_Base", "Armar3");
94 
95  Eigen::Matrix4f leftTcpPoseBase =
96  context->getRobot()->getRobotNode(in.getLeftHandName())->getPoseInRootFrame();
97  Eigen::Matrix4f rightTcpPoseBase =
98  context->getRobot()->getRobotNode(in.getRightHandName())->getPoseInRootFrame();
99 
100  Eigen::Vector3f leftTcpPos;
101  leftTcpPos << leftTcpPoseBase(0, 3), leftTcpPoseBase(1, 3), leftTcpPoseBase(2, 3);
102  Eigen::Vector3f rightTcpPos;
103  rightTcpPos << rightTcpPoseBase(0, 3), rightTcpPoseBase(1, 3), rightTcpPoseBase(2, 3);
104 
105  local.setCurrentRightHandPosition(FramedPosition(rightTcpPos, "Armar3_Base", "Armar3"));
106  local.setCurrentLeftHandPosition(FramedPosition(leftTcpPos, "Armar3_Base", "Armar3"));
107  float velInMillimeterSecond = 20.0;
108  //Eigen::Vector3f curTorqueRightVec = curTorqueRight->toEigen();
109  //Eigen::Vector3f curTorqueLeftVec = curTorqueLeft->toEigen();
110  local.setCurrentLeftHandForces(curForceLeft);
111  local.setCurrentRightHandForces(curForceRight);
112  local.setCurrentRightHandTorques(curTorqueRight);
113  local.setCurrentLeftHandTorques(curTorqueLeft);
114  local.setVelocityInMillimetersSecond(velInMillimeterSecond);
115  local.setCurrentLeftTcpOriVelocity(curVelOriLeft);
116  local.setCurrentRightTcpOriVelocity(curVelOriRight);
117  local.setCurrentLeftTcpPosVelocity(curVelLeft);
118  local.setCurrentRightTcpPosVelocity(curVelRight);
119  local.setLeftHandStopped(false);
120  local.setRightHandStopped(false);
121  local.setLeftHandChecked(false);
122  local.setRightHandChecked(false);
123  //Set initial forces an velocities
124 }
125 
126 void
128 {
129  // put your user code for the execution-phase here
130  // runs in seperate thread, thus can do complex operations
131  // should check constantly whether isRunningTaskStopped() returns true
132 }
133 
134 void
136 {
137  // put your user code for the breaking point here
138  // execution time should be short (<100ms)
139 }
140 
141 void
143 {
145  getContext<CoupledInteractionGroupStatechartContext>();
146  context->getTCPControlUnit()->release();
147  //std::string leftTcpName("Wrist 2 L");
148  //std::string rightTcpName("Wrist 2 R");
149  std::string leftTcpName = in.getLeftHandName();
150  std::string rightTcpName = in.getRightHandName();
151  DatafieldRefPtr forceRefLeft = DatafieldRefPtr::dynamicCast(
152  context->getForceTorqueUnitObserver()->getForceDatafield(leftTcpName));
153  DatafieldRefPtr torqueRefLeft = DatafieldRefPtr::dynamicCast(
154  context->getForceTorqueUnitObserver()->getTorqueDatafield(leftTcpName));
155  DatafieldRefPtr forceRefRight = DatafieldRefPtr::dynamicCast(
156  context->getForceTorqueUnitObserver()->getForceDatafield(rightTcpName));
157  DatafieldRefPtr torqueRefRight = DatafieldRefPtr::dynamicCast(
158  context->getForceTorqueUnitObserver()->getTorqueDatafield(rightTcpName));
159  context->getForceTorqueUnitObserver()->removeFilteredDatafield(forceRefLeft);
160  context->getForceTorqueUnitObserver()->removeFilteredDatafield(forceRefRight);
161  context->getForceTorqueUnitObserver()->removeFilteredDatafield(torqueRefLeft);
162  context->getForceTorqueUnitObserver()->removeFilteredDatafield(torqueRefRight);
163 }
164 
165 // DO NOT EDIT NEXT FUNCTION
166 std::string
168 {
169  return "PlaceTable";
170 }
171 
172 // DO NOT EDIT NEXT FUNCTION
175 {
176  return XMLStateFactoryBasePtr(new PlaceTable(stateData));
177 }
RemoteRobot.h
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
PlaceTable.h
armarx::CoupledInteractionGroup::PlaceTable::Registry
static SubClassRegistry Registry
Definition: PlaceTable.h:51
armarx::CoupledInteractionGroup::PlaceTable::run
void run() override
Definition: PlaceTable.cpp:127
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
IceInternal::Handle< DatafieldRef >
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getRobot
const VirtualRobot::RobotPtr getRobot()
Definition: CoupledInteractionGroupStatechartContext.h:133
armarx::FramedDirection::ChangeFrame
static FramedDirectionPtr ChangeFrame(const VirtualRobot::RobotPtr &robot, const FramedDirection &framedVec, const std::string &newFrame)
Definition: FramedPose.cpp:91
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:146
armarx::CoupledInteractionGroup::PlaceTable::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: PlaceTable.cpp:174
armarx::CoupledInteractionGroup::PlaceTable::onEnter
void onEnter() override
Definition: PlaceTable.cpp:43
armarx::CoupledInteractionGroup::PlaceTable
Definition: PlaceTable.h:37
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getTCPControlUnit
TCPControlUnitInterfacePrx getTCPControlUnit()
Definition: CoupledInteractionGroupStatechartContext.h:157
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
armarx::CoupledInteractionGroup::PlaceTable::onExit
void onExit() override
Definition: PlaceTable.cpp:142
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext
Definition: CoupledInteractionGroupStatechartContext.h:118
armarx::CoupledInteractionGroup::PlaceTable::GetName
static std::string GetName()
Definition: PlaceTable.cpp:167
armarx::VariantType::FramedPosition
const VariantTypeId FramedPosition
Definition: FramedPose.h:38
armarx::CoupledInteractionGroup::PlaceTable::onBreak
void onBreak() override
Definition: PlaceTable.cpp:135
armarx::CoupledInteractionGroup::PlaceTable::PlaceTable
PlaceTable(XMLStateConstructorParams stateData)
Definition: PlaceTable.cpp:37
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27