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