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