TwoArmVisualServoTest.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::VisualServoGroup
19  * @author Markus Grotz ( markus dot grotz 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 "TwoArmVisualServoTest.h"
26 
27 
31 
32 #include <RobotAPI/interface/components/ViewSelectionInterface.h>
33 
34 
35 using namespace armarx;
36 using namespace VisualServoGroup;
37 
39 
40 // DO NOT EDIT NEXT LINE
41 TwoArmVisualServoTest::SubClassRegistry TwoArmVisualServoTest::Registry(TwoArmVisualServoTest::GetName(), &TwoArmVisualServoTest::CreateInstance);
42 
43 
44 
46  XMLStateTemplate<TwoArmVisualServoTest>(stateData), TwoArmVisualServoTestGeneratedBase<TwoArmVisualServoTest>(stateData)
47 {
48 }
49 
50 
51 ChannelRefPtr TwoArmVisualServoTest::getChannelRef(std::string objectName)
52 {
53 
54  VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
55  ChannelRefBasePtr memoryChannel = context->getObjectMemoryObserver()->requestObjectClassRepeated(objectName, 250, armarx::DEFAULT_VIEWTARGET_PRIORITY);
56 
57  if (memoryChannel)
58  {
59  memoryChannel->validate();
60  return ChannelRefPtr::dynamicCast(memoryChannel);
61  }
62  else
63  {
64  ARMARX_ERROR << "unable to get channel ref";
65  return nullptr;
66  }
67 }
68 
70 {
71 
72  std::string leftObjectName = in.getLeftObjectName();
73  local.setLeftObjectMemoryChannel(getChannelRef(leftObjectName));
74 
75  std::string rightObjectName = in.getRightObjectName();
76  if (leftObjectName != rightObjectName)
77  {
78  local.setRightObjectMemoryChannel(getChannelRef(rightObjectName));
79  }
80  else
81  {
82  local.setRightObjectMemoryChannel(local.getLeftObjectMemoryChannel());
83  }
84 
85 
86  std::string leftHandNameInMemory = in.getLeftHandNameInMemory();
87  local.setLeftHandMemoryChannel(getChannelRef(leftHandNameInMemory));
88 
89  std::string rightHandNameInMemory = in.getRightHandNameInMemory();
90  local.setRightHandMemoryChannel(getChannelRef(rightHandNameInMemory));
91 
92  VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
93 
94 
95  // set first view directions manually for initial localization of hands and objects
96  FramedPositionPtr viewTarget;
97  std::string frameName = context->getRobotStateComponent()->getSynchronizedRobot()->getRootNode()->getName();
98  std::string agentName = context->getRobotStateComponent()->getSynchronizedRobot()->getName();
99  Eigen::Vector3f targetPos;
100  targetPos(0) = 0;
101  targetPos(1) = 700;
102  targetPos(2) = 1100;
103  viewTarget = new FramedPosition(targetPos, frameName, agentName);
104  context->getViewSelection()->addManualViewTarget(viewTarget);
105  targetPos(0) = 300;
106  targetPos(1) = 500;
107  targetPos(2) = 1100;
108  viewTarget = new FramedPosition(targetPos, frameName, agentName);
109  context->getViewSelection()->addManualViewTarget(viewTarget);
110  targetPos(0) = 0;
111  targetPos(1) = 700;
112  targetPos(2) = 1100;
113  viewTarget = new FramedPosition(targetPos, frameName, agentName);
114  context->getViewSelection()->addManualViewTarget(viewTarget);
115  targetPos(0) = -300;
116  targetPos(1) = 500;
117  targetPos(2) = 1100;
118  viewTarget = new FramedPosition(targetPos, frameName, agentName);
119  context->getViewSelection()->addManualViewTarget(viewTarget);
120 
121 }
122 
123 
124 
125 // DO NOT EDIT NEXT FUNCTION
127 {
128  return XMLStateFactoryBasePtr(new TwoArmVisualServoTest(stateData));
129 }
130 
armarx::VisualServoGroup::TwoArmVisualServoTest
Definition: TwoArmVisualServoTest.h:34
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
ObjectClass.h
TwoArmVisualServoTest.h
IceInternal::Handle< ChannelRef >
ObjectMemoryObserver.h
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:137
armarx::VisualServoGroup::TwoArmVisualServoTest::Registry
static SubClassRegistry Registry
Definition: TwoArmVisualServoTest.h:45
armarx::VisualServoGroup::TwoArmVisualServoTest::TwoArmVisualServoTest
TwoArmVisualServoTest(XMLStateConstructorParams stateData)
Definition: TwoArmVisualServoTest.cpp:45
MemoryXCoreObjectFactories.h
armarx::VisualServoGroup::TwoArmVisualServoTest::onEnter
void onEnter() override
Definition: TwoArmVisualServoTest.cpp:69
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
armarx::VisualServoGroup::TwoArmVisualServoTest::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: TwoArmVisualServoTest.cpp:126
MemoryXTypesObjectFactories.h
armarx::VariantType::FramedPosition
const VariantTypeId FramedPosition
Definition: FramedPose.h:39
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28