VisualServo.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::FindAndGraspObjectGroup
19  * @author Valerij Wittenbeck ( valerij dot wittenbeck at student dot kit dot edu )
20  * @date 2014
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #include "VisualServo.h"
26 
27 using namespace armarx;
28 using namespace FindAndGraspObjectGroup;
29 
30 // DO NOT EDIT NEXT LINE
31 VisualServo::SubClassRegistry VisualServo::Registry(VisualServo::GetName(),
33 
35  XMLStateTemplate<VisualServo>(stateData)
36 {
37 }
38 
39 void
41 {
42  ARMARX_VERBOSE << "Entering VisualServo::onEnter()";
43 
44  // timeout condition (Failure)
45  float visualServoTimeoutMS = getInput<float>("timeoutTotalMsec");
46  condServoTimeout = setTimeoutEvent(visualServoTimeoutMS, createEvent<Failure>());
47 
48  float minRecognitionLikelihood = getInput<float>("minRecognitionLikelihood");
49 
50  //OLD:
51  /*
52  // object lost condition (Failure) //TODO (maybe): move this to the VSExample (where the condObjectUpdate also is)
53  ChannelRefPtr objectChannel = getInput<ChannelRef>("objectChannel");
54  Literal objectLost(*objectChannel->getDataFieldIdentifier("existenceCertainty"), "smaller", Literal::createParameterList(minRecognitionLikelihood));
55  condObjectLost = installCondition(objectLost, createEvent<Failure>());
56  */
57 
58  // marker lost condition (Failure)
59  ChannelRefPtr markerChannel = getInput<ChannelRef>("markerChannel");
60  Literal markerLost(*markerChannel->getDataFieldIdentifier("existenceCertainty"),
61  "smaller",
62  Literal::createParameterList(minRecognitionLikelihood));
63  condMarkerLost = installCondition(markerLost, createEvent<Failure>());
64 
65  ARMARX_IMPORTANT << "Done VisualServo::onEnter()";
66 }
67 
68 void
70 {
71  // VisualServoContext* visualServoContext = getContext<VisualServoContext>();
72 
73  // std::string robotNodeSetName = getInput<std::string>("kinematicChain");
74  // VirtualRobot::RobotPtr localRobot = RemoteRobot::createLocalClone(visualServoContext->robotStateComponent);
75  // VirtualRobot::RobotNodeSetPtr robotNodeSet = visualServoContext->remoteRobot->getRobotNodeSet(robotNodeSetName);
76  // VirtualRobot::RobotNodeSetPtr robotNodeSet = localRobot->getRobotNodeSet(robotNodeSetName);
77 
78  // Stop the robot
79  // build name value map
80  // NameValueMap targetVelocities;
81  //// NameValueMap targetPositions;
82  // NameControlModeMap controlModes;
83  // const std::vector< VirtualRobot::RobotNodePtr > nodes = robotNodeSet->getAllRobotNodes();
84  // std::vector< VirtualRobot::RobotNodePtr >::const_iterator iter = nodes.begin();
85  // while (iter != nodes.end())
86  // {
87  // targetVelocities.insert(std::make_pair((*iter)->getName(), 0.0f));
88  // controlModes.insert(std::make_pair((*iter)->getName(), eVelocityControl));
89  // iter++;
90  // };
91  // // execute velocities
92  // visualServoContext->kinematicUnitPrx->switchControlMode(controlModes);
93  // visualServoContext->kinematicUnitPrx->setJointVelocities(targetVelocities);
94 
95 
97  //removeCondition(condObjectLost); //TODO (maybe): move this to the VSExample (where the condObjectUpdate also is)
99 
100  ARMARX_VERBOSE << "Done VisualServo::onExit()";
101 }
102 
103 // DO NOT EDIT NEXT FUNCTION
104 std::string
106 {
107  return "VisualServo";
108 }
109 
110 // DO NOT EDIT NEXT FUNCTION
113 {
114  return XMLStateFactoryBasePtr(new VisualServo(stateData));
115 }
armarx::StateUtility::removeCondition
void removeCondition(ConditionIdentifier conditionId)
Utility function to remove an installed condition on the distributed conditionhandler.
Definition: StateUtil.cpp:148
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:187
armarx::FindAndGraspObjectGroup::VisualServo
Definition: VisualServo.h:35
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:190
armarx::FindAndGraspObjectGroup::VisualServo::Registry
static SubClassRegistry Registry
Definition: VisualServo.h:47
armarx::FindAndGraspObjectGroup::VisualServo::VisualServo
VisualServo(XMLStateConstructorParams stateData)
Definition: VisualServo.cpp:34
armarx::FindAndGraspObjectGroup::VisualServo::onEnter
void onEnter() override
Virtual function, in which the behaviour of state is defined, when it is entered. Can be overridden,...
Definition: VisualServo.cpp:40
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
armarx::FindAndGraspObjectGroup::VisualServo::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: VisualServo.cpp:112
armarx::Literal::createParameterList
static VarList createParameterList()
Static helper method to create an empty parameterlist.
Definition: Term.cpp:142
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
IceInternal::Handle< ChannelRef >
armarx::StateUtility::setTimeoutEvent
ActionEventIdentifier setTimeoutEvent(int timeoutDurationMs, const EventPtr &evt)
Utility function to start a timer on the systemObserver and register an event on the conditionHandler...
Definition: StateUtil.cpp:162
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:146
armarx::FindAndGraspObjectGroup::VisualServo::onExit
void onExit() override
Virtual function, in which the behaviour of state is defined, when it is exited. Can be overridden,...
Definition: VisualServo.cpp:69
armarx::StateUtility::installCondition
ConditionIdentifier installCondition(const Term &condition, const EventPtr evt, const std::string &desc="")
Utility function to install a condition on the distributed conditionhandler.
Definition: StateUtil.cpp:102
armarx::FindAndGraspObjectGroup::VisualServo::condMarkerLost
ConditionIdentifier condMarkerLost
Definition: VisualServo.h:53
VisualServo.h
armarx::FindAndGraspObjectGroup::VisualServo::GetName
static std::string GetName()
Definition: VisualServo.cpp:105
armarx::Literal
Definition: Term.h:208
armarx::FindAndGraspObjectGroup::VisualServo::condServoTimeout
ActionEventIdentifier condServoTimeout
Definition: VisualServo.h:52
armarx::StateUtility::removeTimeoutEvent
void removeTimeoutEvent(const ActionEventIdentifier &id)
Definition: StateUtil.cpp:203
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27