MoveTableAdmittanceControl.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::MoveTableAdmittanceControlGroup
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
26#include <VirtualRobot/MathTools.h>
27
29
30
31using namespace armarx;
32using namespace CoupledInteractionGroup;
33
34// DO NOT EDIT NEXT LINE
35MoveTableAdmittanceControl::SubClassRegistry
38
44
45void
47{
49 getContext<CoupledInteractionGroupStatechartContext>();
50
51 Eigen::Vector3f zeroVelVec;
52 zeroVelVec << 0.0, 0.0, 0.0;
53 //std::string leftTcpName("Wrist 2 L");
54 //std::string rightTcpName("Wrist 2 R");
55 std::string leftTcpName = in.getLeftHandName();
56 std::string rightTcpName = in.getRightHandName();
57 //leftTcpName = std::string("Wrist 2 L");
58 //rightTcpName = std::string("Wrist 2 R");
59 DatafieldRefPtr forceRefLeft = DatafieldRefPtr::dynamicCast(
60 context->getForceTorqueUnitObserver()->getForceDatafield(leftTcpName));
61 DatafieldRefPtr torqueRefLeft = DatafieldRefPtr::dynamicCast(
62 context->getForceTorqueUnitObserver()->getTorqueDatafield(leftTcpName));
63 DatafieldRefPtr forceRefRight = DatafieldRefPtr::dynamicCast(
64 context->getForceTorqueUnitObserver()->getForceDatafield(rightTcpName));
65 DatafieldRefPtr torqueRefRight = DatafieldRefPtr::dynamicCast(
66 context->getForceTorqueUnitObserver()->getTorqueDatafield(rightTcpName));
67 forceRefLeft = DatafieldRefPtr::dynamicCast(
68 context->getForceTorqueUnitObserver()->createNulledDatafield(forceRefLeft));
69 forceRefRight = DatafieldRefPtr::dynamicCast(
70 context->getForceTorqueUnitObserver()->createNulledDatafield(forceRefRight));
71 torqueRefLeft = DatafieldRefPtr::dynamicCast(
72 context->getForceTorqueUnitObserver()->createNulledDatafield(torqueRefLeft));
73 torqueRefRight = DatafieldRefPtr::dynamicCast(
74 context->getForceTorqueUnitObserver()->createNulledDatafield(torqueRefRight));
75 FramedDirectionPtr curForceLeft = forceRefLeft->getDataField()->get<FramedDirection>();
76 curForceLeft = FramedDirection::ChangeFrame(context->getRobot(), *curForceLeft, "Armar3_Base");
77 FramedDirectionPtr curForceRight = forceRefRight->getDataField()->get<FramedDirection>();
78 curForceRight =
79 FramedDirection::ChangeFrame(context->getRobot(), *curForceRight, "Armar3_Base");
80 FramedDirectionPtr curTorqueLeft = torqueRefLeft->getDataField()->get<FramedDirection>();
81 curTorqueLeft =
82 FramedDirection::ChangeFrame(context->getRobot(), *curTorqueLeft, "Armar3_Base");
83 FramedDirectionPtr curTorqueRight = torqueRefRight->getDataField()->get<FramedDirection>();
84 curTorqueRight =
85 FramedDirection::ChangeFrame(context->getRobot(), *curTorqueRight, "Armar3_Base");
86
87 Eigen::Matrix4f leftTcpPoseBase =
88 context->getRobot()->getRobotNode(in.getLeftHandName())->getPoseInRootFrame();
89 Eigen::Matrix4f rightTcpPoseBase =
90 context->getRobot()->getRobotNode(in.getRightHandName())->getPoseInRootFrame();
91
92 Eigen::Vector3f desiredLeftRPY;
93 VirtualRobot::MathTools::eigen4f2rpy(leftTcpPoseBase, desiredLeftRPY);
94 Eigen::Vector3f desiredRightRPY;
95 VirtualRobot::MathTools::eigen4f2rpy(rightTcpPoseBase, desiredRightRPY);
96
97 Eigen::Vector3f platformPose;
98 armarx::ChannelRefPtr poseRef =
99 context->getChannelRef(context->getPlatformUnitObserverName(), "platformPose");
100 platformPose(0) = poseRef->getDataField("positionX")->getFloat();
101 platformPose(1) = poseRef->getDataField("positionY")->getFloat();
102 platformPose(2) = poseRef->getDataField("rotation")->getFloat();
103 local.setInitialPlatformPose(Vector3(platformPose));
104 local.setDesiredLeftTcpPose(FramedPose(leftTcpPoseBase, "Armar3_Base", "Armar3"));
105 local.setDesiredRightTcpPose(FramedPose(rightTcpPoseBase, "Armar3_Base", "Armar3"));
106 local.setDesiredLeftTcpOrientation(FramedDirection(desiredLeftRPY, "Armar3_Base", "Armar3"));
107 local.setDesiredRightTcpOrientation(FramedDirection(desiredRightRPY, "Armar3_Base", "Armar3"));
108 local.setCurrentLeftTcpOriVelocity(FramedDirection(zeroVelVec, "Armar3_Base", "Armar3"));
109 local.setCurrentLeftTcpPosVelocity(FramedDirection(zeroVelVec, "Armar3_Base", "Armar3"));
110 local.setCurrentRightTcpOriVelocity(FramedDirection(zeroVelVec, "Armar3_Base", "Armar3"));
111 local.setCurrentRightTcpPosVelocity(FramedDirection(zeroVelVec, "Armar3_Base", "Armar3"));
112 local.setCurrentPlatformVelocity(Vector3(zeroVelVec));
113 local.setTimestamp(TimestampVariant::nowPtr());
114 local.setinitialForcesReset(true);
115 local.setcounter(0);
116}
117
118void
120{
122 getContext<CoupledInteractionGroupStatechartContext>();
123 //std::string leftTcpName("Wrist 2 L");
124 //std::string rightTcpName("Wrist 2 R");
125 std::string leftTcpName = in.getLeftHandName();
126 std::string rightTcpName = in.getRightHandName();
127 DatafieldRefPtr forceRefLeft = DatafieldRefPtr::dynamicCast(
128 context->getForceTorqueUnitObserver()->getForceDatafield(leftTcpName));
129 DatafieldRefPtr torqueRefLeft = DatafieldRefPtr::dynamicCast(
130 context->getForceTorqueUnitObserver()->getTorqueDatafield(leftTcpName));
131 DatafieldRefPtr forceRefRight = DatafieldRefPtr::dynamicCast(
132 context->getForceTorqueUnitObserver()->getForceDatafield(rightTcpName));
133 DatafieldRefPtr torqueRefRight = DatafieldRefPtr::dynamicCast(
134 context->getForceTorqueUnitObserver()->getTorqueDatafield(rightTcpName));
135 context->getForceTorqueUnitObserver()->removeFilteredDatafield(forceRefLeft);
136 context->getForceTorqueUnitObserver()->removeFilteredDatafield(forceRefRight);
137 context->getForceTorqueUnitObserver()->removeFilteredDatafield(torqueRefLeft);
138 context->getForceTorqueUnitObserver()->removeFilteredDatafield(torqueRefRight);
139
140 // put your user code for the exit point here
141 // execution time should be short (<100ms)
142}
143
144// DO NOT EDIT NEXT FUNCTION
145std::string
147{
148 return "MoveTableAdmittanceControl";
149}
150
151// DO NOT EDIT NEXT FUNCTION
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
FramedDirection is a 3 dimensional direction vector with a reference frame.
Definition FramedPose.h:87
static FramedDirectionPtr ChangeFrame(const VirtualRobot::RobotConstPtr &robot, const FramedDirection &framedVec, const std::string &newFrame)
The FramedPose class.
Definition FramedPose.h:281
ChannelRefPtr getChannelRef(const std::string &observerName, const std::string &channelName) override
static TimestampVariantPtr nowPtr()
The Vector3 class.
Definition Pose.h:113
Class for legacy to stay compatible with old statecharts.
Definition XMLState.h:147
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< FramedDirection > FramedDirectionPtr
Definition FramedPose.h:84
IceInternal::Handle< ChannelRef > ChannelRefPtr
Definition ChannelRef.h:40
IceInternal::Handle< DatafieldRef > DatafieldRefPtr
Definition Observer.h:43
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64