MovingSquareForce.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_TESTING_VISUALTESTCOMMON_MOVINGSQUAREFORCE_H
#define SURGSIM_TESTING_VISUALTESTCOMMON_MOVINGSQUAREFORCE_H
#include <string>
#include "SurgSim/Input/InputConsumerInterface.h"
#include "SurgSim/Input/OutputProducerInterface.h"
#include "SurgSim/DataStructures/DataGroup.h"
#include "SurgSim/Framework/LockedContainer.h"
class MovingSquareForce : public SurgSim::Input::InputConsumerInterface, public SurgSim::Input::OutputProducerInterface
{
public:
MovingSquareForce(const std::string& toolDeviceName, const std::string& squareDeviceName);
void initializeInput(const std::string& device, const SurgSim::DataStructures::DataGroup& inputData) override;
void handleInput(const std::string& device, const SurgSim::DataStructures::DataGroup& inputData) override;
bool requestOutput(const std::string& device, SurgSim::DataStructures::DataGroup* outputData) override;
protected:
void updateTool(const SurgSim::DataStructures::DataGroup& toolInputData);
void updateSquare(const SurgSim::DataStructures::DataGroup& squareInputData);
SurgSim::Math::Vector3d computeForce(const SurgSim::Math::Vector3d& position);
private:
struct SquarePoseVectors
{
SquarePoseVectors();
SurgSim::Math::Vector3d normal;
SurgSim::Math::Vector3d edgeDirectionX;
SurgSim::Math::Vector3d edgeDirectionY;
SurgSim::Math::Vector3d center;
};
const std::string m_toolDeviceName;
const std::string m_squareDeviceName;
SurgSim::DataStructures::DataGroup m_outputData;
double m_squareHalfSize;
double m_surfaceStiffness;
double m_forceLimit;
SurgSim::Framework::LockedContainer<SquarePoseVectors> m_square;
double m_squareNormalDirection;
SurgSim::Math::Vector3d m_tipPoint;
};
#endif // SURGSIM_TESTING_VISUALTESTCOMMON_MOVINGSQUAREFORCE_H
MovingSquareForce::m_square
SurgSim::Framework::LockedContainer< SquarePoseVectors > m_square
Points and directions defined by the pose of the square.
Definition: MovingSquareForce.h:93
MovingSquareForce::m_outputData
SurgSim::DataStructures::DataGroup m_outputData
Internally stored output data (force and torque).
Definition: MovingSquareForce.h:83
MovingSquareForce::m_toolDeviceName
const std::string m_toolDeviceName
Name of the device used as the tool.
Definition: MovingSquareForce.h:78
DataGroup.h
SurgSim::Input::OutputProducerInterface
Interface for a producer that generates device output updates (forces, status LED state...
Definition: OutputProducerInterface.h:33
MovingSquareForce::m_tipPoint
SurgSim::Math::Vector3d m_tipPoint
The location of the "tip" (i.e. interacting point) of the tool, in the local frame relative to the to...
Definition: MovingSquareForce.h:98
MovingSquareForce::SquarePoseVectors::center
SurgSim::Math::Vector3d center
The location of the center of the square in world coordinates.
Definition: MovingSquareForce.h:73
MovingSquareForce::handleInput
void handleInput(const std::string &device, const SurgSim::DataStructures::DataGroup &inputData) override
Notifies the consumer that the application input coming from the device has been updated.
Definition: MovingSquareForce.cpp:65
LockedContainer.h
MovingSquareForce::MovingSquareForce
MovingSquareForce(const std::string &toolDeviceName, const std::string &squareDeviceName)
Constructor.
Definition: MovingSquareForce.cpp:43
MovingSquareForce::m_forceLimit
double m_forceLimit
The maximum force before the application allows the tool to pop through.
Definition: MovingSquareForce.h:90
MovingSquareForce::SquarePoseVectors::normal
SurgSim::Math::Vector3d normal
The unit normal vector of the square.
Definition: MovingSquareForce.h:67
MovingSquareForce::SquarePoseVectors::edgeDirectionY
SurgSim::Math::Vector3d edgeDirectionY
The unit direction along the other pair of edges of the square.
Definition: MovingSquareForce.h:71
MovingSquareForce::requestOutput
bool requestOutput(const std::string &device, SurgSim::DataStructures::DataGroup *outputData) override
Asks the producer to provide output state to the device.
Definition: MovingSquareForce.cpp:116
SurgSim::Input::InputConsumerInterface
Interface for a consumer that monitors device and signal state updates (pose, buttons, etc).
Definition: InputConsumerInterface.h:33
MovingSquareForce
A simple listener to calculate collision force against a square area for the example application...
Definition: MovingSquareForce.h:31
InputConsumerInterface.h
SurgSim::DataStructures::DataGroup
A collection of NamedData objects.
Definition: DataGroup.h:68
MovingSquareForce::updateTool
void updateTool(const SurgSim::DataStructures::DataGroup &toolInputData)
Updates the state of the tool as described by toolInputData.
Definition: MovingSquareForce.cpp:81
OutputProducerInterface.h
MovingSquareForce::SquarePoseVectors::SquarePoseVectors
SquarePoseVectors()
Constructor.
Definition: MovingSquareForce.cpp:34
MovingSquareForce::computeForce
SurgSim::Math::Vector3d computeForce(const SurgSim::Math::Vector3d &position)
Calculates the force as a function of device tip position.
Definition: MovingSquareForce.cpp:122
SurgSim::Framework::LockedContainer
A simple thread-safe data container that can support multiple writers and readers.
Definition: LockedContainer.h:54
MovingSquareForce::m_squareNormalDirection
double m_squareNormalDirection
The current sign of the direction of the normal vector of the square.
Definition: MovingSquareForce.h:95
MovingSquareForce::initializeInput
void initializeInput(const std::string &device, const SurgSim::DataStructures::DataGroup &inputData) override
Set the initial input data group.
Definition: MovingSquareForce.cpp:61
MovingSquareForce::m_squareDeviceName
const std::string m_squareDeviceName
Name of the device used to move the square.
Definition: MovingSquareForce.h:80
SurgSim::Math::Vector3d
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
MovingSquareForce::m_surfaceStiffness
double m_surfaceStiffness
The surface stiffness, in newtons per meter.
Definition: MovingSquareForce.h:88
MovingSquareForce::m_squareHalfSize
double m_squareHalfSize
One half of the edge length of the square we&#39;re colliding against, in meters.
Definition: MovingSquareForce.h:86
MovingSquareForce::updateSquare
void updateSquare(const SurgSim::DataStructures::DataGroup &squareInputData)
Updates the state of the square as described by squareInputData.
Definition: MovingSquareForce.cpp:98
MovingSquareForce::SquarePoseVectors::edgeDirectionX
SurgSim::Math::Vector3d edgeDirectionX
The unit direction along one of the pairs edges of the square.
Definition: MovingSquareForce.h:69
MovingSquareForce::SquarePoseVectors
State defined by the pose of the square.
Definition: MovingSquareForce.h:61