Skip to content

Commit

Permalink
Updating repo with hiro joint velocity and impedance controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
calebescobedo committed May 22, 2024
1 parent 86f2254 commit 4461aa5
Show file tree
Hide file tree
Showing 15 changed files with 951 additions and 3 deletions.
2 changes: 1 addition & 1 deletion franka_control/launch/franka_control.launch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" ?>
<launch>
<arg name="robot_ip" />
<arg name="robot" default="panda" doc="choose your robot. Possible values: [panda, fr3]"/>
<arg name="robot" default="fr3" doc="choose your robot. Possible values: [panda, fr3]"/>
<arg name="arm_id" default="$(arg robot)" />
<arg name="load_gripper" default="true" />
<arg name="xacro_args" default="" />
Expand Down
3 changes: 3 additions & 0 deletions franka_example_controllers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,17 @@ catkin_package(
)

add_library(franka_example_controllers
src/hiro_joint_velocity_example_controller.cpp
src/elbow_example_controller.cpp
src/cartesian_pose_example_controller.cpp
src/cartesian_velocity_example_controller.cpp
src/joint_position_example_controller.cpp
src/joint_velocity_example_controller.cpp
src/model_example_controller.cpp
src/joint_impedance_example_controller.cpp
src/hiro_joint_impedance_example_controller.cpp
src/cartesian_impedance_example_controller.cpp
src/hiro_cartesian_impedance_example_controller.cpp
src/force_example_controller.cpp
src/dual_arm_cartesian_impedance_example_controller.cpp
src/teleop_joint_pd_example_controller.cpp
Expand Down
57 changes: 57 additions & 0 deletions franka_example_controllers/config/franka_example_controllers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ joint_velocity_example_controller:
- $(arg arm_id)_joint5
- $(arg arm_id)_joint6
- $(arg arm_id)_joint7

hiro_joint_velocity_example_controller:
type: franka_example_controllers/HIROJointVelocityExampleController
arm_id: $(arg arm_id)
joint_names:
- $(arg arm_id)_joint1
- $(arg arm_id)_joint2
- $(arg arm_id)_joint3
- $(arg arm_id)_joint4
- $(arg arm_id)_joint5
- $(arg arm_id)_joint6
- $(arg arm_id)_joint7

joint_position_example_controller:
type: franka_example_controllers/JointPositionExampleController
Expand Down Expand Up @@ -49,6 +61,39 @@ force_example_controller:
- $(arg arm_id)_joint6
- $(arg arm_id)_joint7

hiro_joint_impedance_example_controller:
type: franka_example_controllers/HIROJointImpedanceExampleController
arm_id: $(arg arm_id)
joint_names:
- $(arg arm_id)_joint1
- $(arg arm_id)_joint2
- $(arg arm_id)_joint3
- $(arg arm_id)_joint4
- $(arg arm_id)_joint5
- $(arg arm_id)_joint6
- $(arg arm_id)_joint7
k_gains:
- 10.0
- 10.0
- 10.0
- 10.0
- 5.0
- 3.0
- 1.0
d_gains:
- 5.0
- 5.0
- 5.0
- 2.0
- 2.0
- 2.0
- 1.0
radius: 0.1
acceleration_time: 2.0
vel_max: 0.15
publish_rate: 10.0
coriolis_factor: 1.0

joint_impedance_example_controller:
type: franka_example_controllers/JointImpedanceExampleController
arm_id: $(arg arm_id)
Expand Down Expand Up @@ -94,6 +139,18 @@ cartesian_impedance_example_controller:
- $(arg arm_id)_joint6
- $(arg arm_id)_joint7

hiro_cartesian_impedance_example_controller:
type: franka_example_controllers/HIROCartesianImpedanceExampleController
arm_id: $(arg arm_id)
joint_names:
- $(arg arm_id)_joint1
- $(arg arm_id)_joint2
- $(arg arm_id)_joint3
- $(arg arm_id)_joint4
- $(arg arm_id)_joint5
- $(arg arm_id)_joint6
- $(arg arm_id)_joint7

dual_arm_cartesian_impedance_example_controller:
type: franka_example_controllers/DualArmCartesianImpedanceExampleController
right:
Expand Down
15 changes: 15 additions & 0 deletions franka_example_controllers/franka_example_controllers_plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<description>
A controller that executes a short motion based on joint velocities to demonstrate correct usage
</description>
</class>
<class name="franka_example_controllers/HIROJointVelocityExampleController" type="franka_example_controllers::HIROJointVelocityExampleController" base_class_type="controller_interface::ControllerBase">
<description>
Starts ros message controller interface for the HIRO lab
</description>
</class>
<class name="franka_example_controllers/JointPositionExampleController" type="franka_example_controllers::JointPositionExampleController" base_class_type="controller_interface::ControllerBase">
<description>
Expand Down Expand Up @@ -34,11 +39,21 @@
A controller that tracks a cartesian path with a joint impedance controller that compensates coriolis torques. The torque commands are compared to measured torques in Console outputs.
</description>
</class>
<class name="franka_example_controllers/HIROJointImpedanceExampleController" type="franka_example_controllers::HIROJointImpedanceExampleController" base_class_type="controller_interface::ControllerBase">
<description>
A controller that tracks a cartesian path with a joint impedance controller that compensates coriolis torques. The torque commands are compared to measured torques in Console outputs.
</description>
</class>
<class name="franka_example_controllers/CartesianImpedanceExampleController" type="franka_example_controllers::CartesianImpedanceExampleController" base_class_type="controller_interface::ControllerBase">
<description>
A controller that renders a spring damper system in cartesian space. Compliance parameters and the equilibrium pose can be modified online with dynamic reconfigure and an interactive marker respectively.
</description>
</class>
<class name="franka_example_controllers/HIROCartesianImpedanceExampleController" type="franka_example_controllers::HIROCartesianImpedanceExampleController" base_class_type="controller_interface::ControllerBase">
<description>
A controller that renders a spring damper system in cartesian space. Compliance parameters and the equilibrium pose can be modified online with dynamic reconfigure and an interactive marker respectively.
</description>
</class>
<class name="franka_example_controllers/ForceExampleController" type="franka_example_controllers::ForceExampleController" base_class_type="controller_interface::ControllerBase">
<description>
A PI controller that applies a force corresponding to a user-provided desired mass in the z axis. The desired mass value can be modified online with dynamic reconfigure.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) 2017 Franka Emika GmbH
// Use of this source code is governed by the Apache-2.0 license, see LICENSE
#pragma once

#include <memory>
#include <mutex>
#include <string>
#include <vector>

#include <controller_interface/multi_interface_controller.h>
#include <dynamic_reconfigure/server.h>
#include <geometry_msgs/PoseStamped.h>
#include <hardware_interface/joint_command_interface.h>
#include <hardware_interface/robot_hw.h>
#include <ros/node_handle.h>
#include <ros/time.h>
#include <Eigen/Dense>

#include <franka_example_controllers/compliance_paramConfig.h>
#include <franka_hw/franka_model_interface.h>
#include <franka_hw/franka_state_interface.h>

namespace franka_example_controllers {

class HIROCartesianImpedanceExampleController : public controller_interface::MultiInterfaceController<
franka_hw::FrankaModelInterface,
hardware_interface::EffortJointInterface,
franka_hw::FrankaStateInterface> {
public:
bool init(hardware_interface::RobotHW* robot_hw, ros::NodeHandle& node_handle) override;
void starting(const ros::Time&) override;
void update(const ros::Time&, const ros::Duration& period) override;

private:
// Saturation
Eigen::Matrix<double, 7, 1> saturateTorqueRate(
const Eigen::Matrix<double, 7, 1>& tau_d_calculated,
const Eigen::Matrix<double, 7, 1>& tau_J_d); // NOLINT (readability-identifier-naming)

std::unique_ptr<franka_hw::FrankaStateHandle> state_handle_;
std::unique_ptr<franka_hw::FrankaModelHandle> model_handle_;
std::vector<hardware_interface::JointHandle> joint_handles_;

double filter_params_{0.005};
double nullspace_stiffness_{20.0};
double nullspace_stiffness_target_{20.0};
const double delta_tau_max_{1.0};
Eigen::Matrix<double, 6, 6> cartesian_stiffness_;
Eigen::Matrix<double, 6, 6> cartesian_stiffness_target_;
Eigen::Matrix<double, 6, 6> cartesian_damping_;
Eigen::Matrix<double, 6, 6> cartesian_damping_target_;
Eigen::Matrix<double, 7, 1> q_d_nullspace_;
Eigen::Vector3d position_d_;
Eigen::Quaterniond orientation_d_;
std::mutex position_and_orientation_d_target_mutex_;
Eigen::Vector3d position_d_target_;
Eigen::Quaterniond orientation_d_target_;

// Dynamic reconfigure
std::unique_ptr<dynamic_reconfigure::Server<franka_example_controllers::compliance_paramConfig>>
dynamic_server_compliance_param_;
ros::NodeHandle dynamic_reconfigure_compliance_param_node_;
void complianceParamCallback(franka_example_controllers::compliance_paramConfig& config,
uint32_t level);

// Equilibrium pose subscriber
ros::Subscriber sub_equilibrium_pose_;
void equilibriumPoseCallback(const geometry_msgs::PoseStampedConstPtr& msg);
};

} // namespace franka_example_controllers
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) 2017 Franka Emika GmbH
// Use of this source code is governed by the Apache-2.0 license, see LICENSE
#pragma once

#include <memory>
#include <string>
#include <vector>
#include <mutex>

#include <controller_interface/multi_interface_controller.h>
#include <hardware_interface/joint_command_interface.h>
#include <hardware_interface/robot_hw.h>
#include <realtime_tools/realtime_publisher.h>
#include <ros/node_handle.h>
#include <ros/time.h>

#include <franka_example_controllers/JointTorqueComparison.h>
#include <franka_hw/franka_cartesian_command_interface.h>
#include <franka_hw/franka_model_interface.h>
#include <franka_hw/trigger_rate.h>
#include <sensor_msgs/JointState.h>
#include <std_msgs/Float32MultiArray.h>

namespace franka_example_controllers {

class HIROJointImpedanceExampleController : public controller_interface::MultiInterfaceController<
franka_hw::FrankaModelInterface,
hardware_interface::EffortJointInterface,
franka_hw::FrankaPoseCartesianInterface> {
public:
bool init(hardware_interface::RobotHW* robot_hw, ros::NodeHandle& node_handle) override;
void starting(const ros::Time&) override;
void update(const ros::Time&, const ros::Duration& period) override;

private:
// Saturation
std::array<double, 7> saturateTorqueRate(
const std::array<double, 7>& tau_d_calculated,
const std::array<double, 7>& tau_J_d); // NOLINT (readability-identifier-naming)

std::unique_ptr<franka_hw::FrankaCartesianPoseHandle> cartesian_pose_handle_;
std::unique_ptr<franka_hw::FrankaModelHandle> model_handle_;
std::vector<hardware_interface::JointHandle> joint_handles_;

static constexpr double kDeltaTauMax{1.0};
double radius_{0.1};
double acceleration_time_{2.0};
double vel_max_{0.05};
double angle_{0.0};
double vel_current_{0.0};

std::vector<double> k_gains_;
std::vector<double> d_gains_;
double coriolis_factor_{1.0};
std::array<double, 7> dq_filtered_;
std::array<double, 16> initial_pose_;

franka_hw::TriggerRate rate_trigger_{1.0};
std::array<double, 7> last_tau_d_{};
realtime_tools::RealtimePublisher<JointTorqueComparison> torques_publisher_;
// Added by Caleb E.
std::mutex joint_position_and_velocity_d_target_mutex_;
std::vector<double> joint_positions_{0,0,0,0,0,0,0};
bool callback_done_once = false;
// void jointCommandCb(const sensor_msgs::JointState::ConstPtr& joint_pos_commands);
void jointCommandCb(const std_msgs::Float32MultiArray::ConstPtr& joint_pos_commands);
ros::Subscriber sub_command_;
};

} // namespace franka_example_controllers
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2017 Franka Emika GmbH
// Use of this source code is governed by the Apache-2.0 license, see LICENSE
#pragma once

#include <string>
#include <vector>

#include <controller_interface/multi_interface_controller.h>
#include <franka_hw/franka_state_interface.h>
#include <hardware_interface/joint_command_interface.h>
#include <hardware_interface/robot_hw.h>
#include <ros/node_handle.h>
#include <ros/time.h>
#include <sensor_msgs/JointState.h>

namespace franka_example_controllers {

class HIROJointVelocityExampleController : public controller_interface::MultiInterfaceController<
hardware_interface::VelocityJointInterface,
franka_hw::FrankaStateInterface> {
public:
bool init(hardware_interface::RobotHW* robot_hardware, ros::NodeHandle& node_handle) override;
void update(const ros::Time&, const ros::Duration& period) override;
void starting(const ros::Time&) override;
void stopping(const ros::Time&) override;

private:
hardware_interface::VelocityJointInterface* velocity_joint_interface_;
std::vector<hardware_interface::JointHandle> velocity_joint_handles_;
ros::Duration elapsed_time_;
bool first_sample_taken;
void jointCommandCb(const sensor_msgs::JointState::ConstPtr& joint_pos_commands);
ros::Subscriber sub_command_;
std::unique_ptr<franka_hw::FrankaStateHandle> state_handle_;
int last_time_called;
// std::array<double, 7> joint_velocities{};
std::vector<double> joint_positions_{0,0,0,0,0,0,0};
float p_ = 1.9;
float d_ = 0.0;
// float curr_error_;
std::vector<double> prev_error_{0,0,0,0,0,0,0};
std::vector<double> curr_error_{0,0,0,0,0,0,0};
bool callback_done_once = false;
// franka::RobotState robot_state
};

} // namespace franka_example_controllers
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" ?>
<launch>
<arg name="robot" default="fr3" doc="choose your robot. Possible values: [panda, fr3]"/>
<arg name="arm_id" default="$(arg robot)" />
<include file="$(find franka_control)/launch/franka_control.launch" pass_all_args="true"/>
<rosparam command="load" file="$(find franka_example_controllers)/config/franka_example_controllers.yaml" subst_value="true" />
<node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false" output="screen" args="hiro_cartesian_impedance_example_controller"/>
<node pkg="rviz" type="rviz" output="screen" name="rviz" args="-d $(find franka_example_controllers)/launch/rviz/franka_description_with_marker.rviz -f $(arg arm_id)_link0 --splash-screen $(find franka_visualization)/splash.png"/>
<node name="interactive_marker" pkg="franka_example_controllers" type="interactive_marker.py" required="true" output="screen">
<param name="link_name" value="$(arg arm_id)_link0" />
<remap from="equilibrium_pose" to="/hiro_cartesian_impedance_example_controller/equilibrium_pose" />
</node>
<node name="rqt_reconfigure" pkg="rqt_reconfigure" type="rqt_reconfigure" required="false" />
</launch>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" ?>
<launch>
<arg name="robot" default="fr3" doc="choose your robot. Possible values: [panda, fr3]"/>
<arg name="arm_id" default="$(arg robot)" />
<include file="$(find franka_control)/launch/franka_control.launch" pass_all_args="true"/>
<rosparam command="load" file="$(find franka_example_controllers)/config/franka_example_controllers.yaml" subst_value="true" />
<node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false" output="screen" args="hiro_joint_impedance_example_controller"/>
<node pkg="rviz" type="rviz" output="screen" name="rviz" args="-d $(find franka_example_controllers)/launch/robot.rviz -f $(arg arm_id)_link0 --splash-screen $(find franka_visualization)/splash.png"/>
</launch>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" ?>
<launch>
<arg name="robot_ip" default="192.168.0.198"/>
<arg name="robot" default="fr3" doc="choose your robot. Possible values: [panda, fr3]"/>
<arg name="arm_id" default="$(arg robot)" />
<!-- <arg name="load_gripper" default="true" /> -->
<include file="$(find franka_control)/launch/franka_control.launch" pass_all_args="true" />
<rosparam command="load" file="$(find franka_example_controllers)/config/franka_example_controllers.yaml" subst_value="true" />
<node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false" output="screen" args="hiro_joint_velocity_example_controller"/> <node pkg="rviz" type="rviz" output="screen" name="rviz" args="-d $(find franka_example_controllers)/launch/skin_demo.rviz -f $(arg arm_id)_link0 splash-screen $(find franka_visualization)/splash.png"/>
</launch>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" ?>
<launch>
<arg name="robot" default="panda" doc="choose your robot. Possible values: [panda, fr3]"/>
<arg name="robot" default="fr3" doc="choose your robot. Possible values: [panda, fr3]"/>
<arg name="arm_id" default="$(arg robot)" />
<include file="$(find franka_control)/launch/franka_control.launch" pass_all_args="true"/>
<rosparam command="load" file="$(find franka_example_controllers)/config/franka_example_controllers.yaml" subst_value="true" />
Expand Down
2 changes: 1 addition & 1 deletion franka_example_controllers/launch/move_to_start.launch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" ?>
<launch>
<arg name="robot_ip" />
<arg name="arm_id" default="panda" />
<arg name="arm_id" default="fr3" />
<arg name="transmission" default="effort" doc="The type of position control to use (either 'position' or 'effort')" />

<include file="$(find franka_control)/launch/franka_control.launch" pass_all_args="true">
Expand Down
Loading

0 comments on commit 4461aa5

Please sign in to comment.