An example showing how to generate a Cartesian velocity motion with an external control loop.
An example showing how to generate a Cartesian velocity motion with an external control loop.
#include <cmath>
#include <iostream>
int main(int argc, char** argv) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " <robot-hostname>" << std::endl;
return -1;
}
try {
setDefaultBehavior(robot);
std::array<double, 7> q_goal = {{0, -M_PI_4, 0, -3 * M_PI_4, 0, M_PI_2, M_PI_4}};
std::cout << "WARNING: This example will move the robot! "
<< "Please make sure to have the user stop button at hand!" << std::endl
<< "Press Enter to continue..." << std::endl;
std::cin.ignore();
std::cout << "Finished moving to initial joint configuration." << std::endl;
std::array<double, 7> lower_torque_thresholds_nominal{
{25.0, 25.0, 22.0, 20.0, 19.0, 17.0, 14.}};
std::array<double, 7> upper_torque_thresholds_nominal{
{35.0, 35.0, 32.0, 30.0, 29.0, 27.0, 24.0}};
std::array<double, 7> lower_torque_thresholds_acceleration{
{25.0, 25.0, 22.0, 20.0, 19.0, 17.0, 14.0}};
std::array<double, 7> upper_torque_thresholds_acceleration{
{35.0, 35.0, 32.0, 30.0, 29.0, 27.0, 24.0}};
std::array<double, 6> lower_force_thresholds_nominal{{30.0, 30.0, 30.0, 25.0, 25.0, 25.0}};
std::array<double, 6> upper_force_thresholds_nominal{{40.0, 40.0, 40.0, 35.0, 35.0, 35.0}};
std::array<double, 6> lower_force_thresholds_acceleration{{30.0, 30.0, 30.0, 25.0, 25.0, 25.0}};
std::array<double, 6> upper_force_thresholds_acceleration{{40.0, 40.0, 40.0, 35.0, 35.0, 35.0}};
lower_torque_thresholds_acceleration, upper_torque_thresholds_acceleration,
lower_torque_thresholds_nominal, upper_torque_thresholds_nominal,
lower_force_thresholds_acceleration, upper_force_thresholds_acceleration,
lower_force_thresholds_nominal, upper_force_thresholds_nominal);
double time_max = 4.0;
double v_max = 0.1;
double angle = M_PI / 4.0;
double time = 0.0;
time += period.toSec();
double cycle = std::floor(pow(-1.0, (time - std::fmod(time, time_max)) / time_max));
double v = cycle * v_max / 2.0 * (1.0 - std::cos(2.0 * M_PI / time_max * time));
double v_x = std::cos(angle) * v;
double v_z = -std::sin(angle) * v;
if (time >= 2 * time_max) {
std::cout << std::endl << "Finished motion, shutting down example" << std::endl;
return franka::MotionFinished(output);
}
return output;
};
bool motion_finished = false;
research_interface::robot::Move::ControllerMode::kJointImpedance);
while (!motion_finished) {
auto read_once_return = active_control->readOnce();
auto robot_state = read_once_return.first;
auto duration = read_once_return.second;
auto cartesian_velocities = callback_control(robot_state, duration);
motion_finished = cartesian_velocities.motion_finished;
active_control->writeOnce(cartesian_velocities);
}
std::cout << e.what() << std::endl;
return -1;
}
return 0;
}
Implements the ActiveControlBase abstract class.
Contains the franka::ActiveMotionGenerator type.
An example showing how to generate a joint pose motion to a goal position.
Definition examples_common.h:31
Stores values for Cartesian velocity motion generation.
Definition control_types.h:211
Represents a duration with millisecond resolution.
Definition duration.h:19
Maintains a network connection to the robot, provides the current robot state, gives access to the mo...
Definition robot.h:68
void control(std::function< Torques(const RobotState &, franka::Duration)> control_callback, bool limit_rate=false, double cutoff_frequency=kDefaultCutoffFrequency)
Starts a control loop for sending joint-level torque commands.
void setCollisionBehavior(const std::array< double, 7 > &lower_torque_thresholds_acceleration, const std::array< double, 7 > &upper_torque_thresholds_acceleration, const std::array< double, 7 > &lower_torque_thresholds_nominal, const std::array< double, 7 > &upper_torque_thresholds_nominal, const std::array< double, 6 > &lower_force_thresholds_acceleration, const std::array< double, 6 > &upper_force_thresholds_acceleration, const std::array< double, 6 > &lower_force_thresholds_nominal, const std::array< double, 6 > &upper_force_thresholds_nominal)
Changes the collision behavior.
virtual std::unique_ptr< ActiveControlBase > startCartesianVelocityControl(const research_interface::robot::Move::ControllerMode &control_type)
Starts a new cartesian velocity motion generator.
void setJointImpedance(const std::array< double, 7 > &K_theta)
Sets the impedance for each joint in the internal controller.
Contains common types and functions for the examples.
Contains exception definitions.
Contains the franka::Robot type.
Base class for all exceptions used by libfranka.
Definition exception.h:20
Describes the robot state.
Definition robot_state.h:34