franka_gripper_sim.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <functional>
4 #include <mutex>
5 
7 #include <control_msgs/GripperCommandAction.h>
8 #include <control_toolbox/pid.h>
10 #include <franka_gripper/GraspAction.h>
11 #include <franka_gripper/GraspEpsilon.h>
12 #include <franka_gripper/HomingAction.h>
13 #include <franka_gripper/MoveAction.h>
14 #include <franka_gripper/StopAction.h>
15 #include <franka_hw/trigger_rate.h>
19 #include <ros/time.h>
20 #include <sensor_msgs/JointState.h>
21 
22 namespace franka_gazebo {
23 
24 const double kMaxFingerWidth = 0.08;
25 
27 const double kDefaultMoveWidthTolerance = 0.001;
28 
31 
33 const double kDefaultGripperActionSpeed = 0.1;
34 
36 const double kGraspRestingThreshold = 0.003;
37 
39 const int kGraspConsecutiveSamples = 10;
40 
62  : public controller_interface::Controller<hardware_interface::EffortJointInterface> {
63  public:
64  enum State {
65  IDLE,
66  HOLDING,
68  MOVING,
71  };
74 
75  struct Config {
76  double width_desired;
77  double speed_desired;
78  double force_desired;
79  franka_gripper::GraspEpsilon tolerance;
80  };
81 
83  void starting(const ros::Time&) override;
84  void update(const ros::Time& now, const ros::Duration& period) override;
85 
86  private:
87  State state_ = State::IDLE;
89 
96 
97  std::mutex mutex_;
98 
99  // Configurable by parameters
105 
107  std::unique_ptr<actionlib::SimpleActionServer<franka_gripper::StopAction>> action_stop_;
108  std::unique_ptr<actionlib::SimpleActionServer<franka_gripper::HomingAction>> action_homing_;
109  std::unique_ptr<actionlib::SimpleActionServer<franka_gripper::MoveAction>> action_move_;
110  std::unique_ptr<actionlib::SimpleActionServer<franka_gripper::GraspAction>> action_grasp_;
111  std::unique_ptr<actionlib::SimpleActionServer<control_msgs::GripperCommandAction>> action_gc_;
112 
113  void setState(const State&& state);
114  void setConfig(const Config&& config);
115  void transition(const State&& state, const Config&& config);
116 
119  double q_d,
120  double dq_d,
121  double f_d,
122  const ros::Duration& period);
123 
130  void interrupt(const std::string& message, const State& except);
131 
132  void waitUntilStateChange();
133 
134  void onStopGoal(const franka_gripper::StopGoalConstPtr& goal);
135  void onHomingGoal(const franka_gripper::HomingGoalConstPtr& goal);
136  void onMoveGoal(const franka_gripper::MoveGoalConstPtr& goal);
137  void onGraspGoal(const franka_gripper::GraspGoalConstPtr& goal);
138  void onGripperActionGoal(const control_msgs::GripperCommandGoalConstPtr& goal);
139 
149  bool grasp(double width, double speed, double force, const franka_gripper::GraspEpsilon& epsilon);
150 
157  bool move(double width, double speed);
158 };
159 } // namespace franka_gazebo
void setConfig(const Config &&config)
void starting(const ros::Time &) override
std::unique_ptr< actionlib::SimpleActionServer< franka_gripper::HomingAction > > action_homing_
double force_desired
Desired force with which to grasp objects, if grasps succeed [N].
void control(hardware_interface::JointHandle &joint, control_toolbox::Pid &, double q_d, double dq_d, double f_d, const ros::Duration &period)
const double kDefaultGripperActionWidthTolerance
When width between fingers is below this, the gripper action succeeds [m].
Gripper is not actively controlled, but tracks the other finger to simulate a mimicked joint...
const int kGraspConsecutiveSamples
How many times the speed has to drop below resting threshold before the grasping will be checked...
Simulate the franka_gripper_node.
void onGraspGoal(const franka_gripper::GraspGoalConstPtr &goal)
void onMoveGoal(const franka_gripper::MoveGoalConstPtr &goal)
bool move(double width, double speed)
libfranka-like method to move the gripper to a certain position
std::unique_ptr< actionlib::SimpleActionServer< franka_gripper::GraspAction > > action_grasp_
Gripper is tracking a desired position and velocity.
const double kDefaultGripperActionSpeed
How fast shall the gripper execute gripper command actions? [m/s].
void onHomingGoal(const franka_gripper::HomingGoalConstPtr &goal)
franka_gripper::GraspEpsilon tolerance
Tolerance range to check if grasping succeeds.
realtime_tools::RealtimePublisher< sensor_msgs::JointState > pub_
double width_desired
Desired width between both fingers [m].
double tolerance_gripper_action_
[m] inner + outer position tolerances used during gripper action
bool init(hardware_interface::EffortJointInterface *hw, ros::NodeHandle &nh) override
void update(const ros::Time &now, const ros::Duration &period) override
franka_hw::TriggerRate rate_trigger_
Gripper is holding position and tracking zero velocity while mainting a desired force.
hardware_interface::JointHandle finger1_
void transition(const State &&state, const Config &&config)
double tolerance_move_
[m] inner + outer position tolerances used during grasp
bool grasp(double width, double speed, double force, const franka_gripper::GraspEpsilon &epsilon)
libfranka-like method to grasp an object with the gripper
std::unique_ptr< actionlib::SimpleActionServer< franka_gripper::MoveAction > > action_move_
Gripper is tracking a desired position and velocity.
std::unique_ptr< actionlib::SimpleActionServer< control_msgs::GripperCommandAction > > action_gc_
const double kGraspRestingThreshold
Below which speed the target width should be checked to abort or succeed the grasp action [m/s]...
const double kMaxFingerWidth
void setState(const State &&state)
void interrupt(const std::string &message, const State &except)
Interrupt any running action server unless the gripper is currently in a specific state...
const double kDefaultMoveWidthTolerance
When width between fingers is below this, the move action succeeds [m].
double speed_desired
Desired magnitude of the speed with which fingers should move [m/s].
void onGripperActionGoal(const control_msgs::GripperCommandGoalConstPtr &goal)
void onStopGoal(const franka_gripper::StopGoalConstPtr &goal)
hardware_interface::JointHandle finger2_
std::unique_ptr< actionlib::SimpleActionServer< franka_gripper::StopAction > > action_stop_


franka_gazebo
Author(s): Franka Emika GmbH
autogenerated on Mon Sep 19 2022 03:06:05