[moveit servo]: Scara-like robot always giving "Very close to a singularity, emergency stop" #3477
Unanswered
jintaoChan
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem details
I followed the direction moveit servo to setup my scara-like robot.
However the twist command keep giving "Very close to a singularity, emergency stop".
Solutions I've tried
Way to reproduce
My moveit_config is upload. My control program is list followed.
Here the key part of my code
launch file
control program(modified this file)
#include
#include <control_msgs/msg/joint_jog.hpp>
#include <geometry_msgs/msg/twist_stamped.hpp>
#include <moveit_msgs/srv/servo_command_type.hpp>
#include <rclcpp/rclcpp.hpp>
#include <signal.h>
#include <stdio.h>
#ifndef WIN32
#include <termios.h>
#include <unistd.h>
#else
#include <conio.h>
#endif
// Define used keys
namespace
{
constexpr int8_t KEYCODE_RIGHT = 0x43;
constexpr int8_t KEYCODE_LEFT = 0x44;
constexpr int8_t KEYCODE_UP = 0x41;
constexpr int8_t KEYCODE_DOWN = 0x42;
constexpr int8_t KEYCODE_PERIOD = 0x2E;
constexpr int8_t KEYCODE_SEMICOLON = 0x3B;
constexpr int8_t KEYCODE_1 = 0x31;
constexpr int8_t KEYCODE_2 = 0x32;
constexpr int8_t KEYCODE_3 = 0x33;
constexpr int8_t KEYCODE_4 = 0x34;
constexpr int8_t KEYCODE_5 = 0x35;
constexpr int8_t KEYCODE_6 = 0x36;
constexpr int8_t KEYCODE_7 = 0x37;
constexpr int8_t KEYCODE_Q = 0x71;
constexpr int8_t KEYCODE_R = 0x72;
constexpr int8_t KEYCODE_J = 0x6A;
constexpr int8_t KEYCODE_T = 0x74;
constexpr int8_t KEYCODE_W = 0x77;
constexpr int8_t KEYCODE_E = 0x65;
} // namespace
// Some constants used in the Servo Teleop demo
namespace
{
const std::string TWIST_TOPIC = "/servo_node/delta_twist_cmds";
const std::string JOINT_TOPIC = "/servo_node/delta_joint_cmds";
const size_t ROS_QUEUE_SIZE = 10;
const std::string PLANNING_FRAME_ID = "base_link";
const std::string EE_FRAME_ID = "link5";
} // namespace
// A class for reading the key inputs from the terminal
class KeyboardReader
{
public:
KeyboardReader() : file_descriptor_(0)
{
#ifndef WIN32
// get the console in raw mode
tcgetattr(file_descriptor_, &cooked_);
struct termios raw;
memcpy(&raw, &cooked_, sizeof(struct termios));
raw.c_lflag &= ~(ICANON | ECHO);
// Setting a new line, then end of file
raw.c_cc[VEOL] = 1;
raw.c_cc[VEOF] = 2;
tcsetattr(file_descriptor_, TCSANOW, &raw);
#endif
}
void readOne(char* c)
{
#ifndef WIN32
int rc = read(file_descriptor_, c, 1);
if (rc < 0)
{
throw std::runtime_error("read failed");
}
#else
*c = static_cast(getch());
#endif
}
void shutdown()
{
#ifndef WIN32
tcsetattr(file_descriptor, TCSANOW, &cooked_);
#endif
}
private:
int file_descriptor_;
#ifndef WIN32
struct termios cooked_;
#endif
};
// Converts key-presses to Twist or Jog commands for Servo, in lieu of a controller
class KeyboardServo
{
public:
KeyboardServo();
int keyLoop();
private:
void spin();
rclcpp::Node::SharedPtr nh_;
rclcpp::Publisher<geometry_msgs::msg::TwistStamped>::SharedPtr twist_pub_;
rclcpp::Publisher<control_msgs::msg::JointJog>::SharedPtr joint_pub_;
rclcpp::Client<moveit_msgs::srv::ServoCommandType>::SharedPtr switch_input_;
std::shared_ptr<moveit_msgs::srv::ServoCommandType::Request> request_;
double joint_vel_cmd_;
std::string command_frame_id_;
};
KeyboardServo::KeyboardServo() : joint_vel_cmd_(1.0), command_frame_id_{ PLANNING_FRAME_ID }
{
nh_ = rclcpp::Node::make_shared("servo_keyboard_input");
twist_pub_ = nh_->create_publisher<geometry_msgs::msg::TwistStamped>(TWIST_TOPIC, ROS_QUEUE_SIZE);
joint_pub_ = nh_->create_publisher<control_msgs::msg::JointJog>(JOINT_TOPIC, ROS_QUEUE_SIZE);
// Client for switching input types
switch_input_ = nh_->create_client<moveit_msgs::srv::ServoCommandType>("servo_node/switch_command_type");
}
KeyboardReader input;
void quit(int sig)
{
(void)sig;
input.shutdown();
rclcpp::shutdown();
exit(0);
}
int main(int argc, char** argv)
{
rclcpp::init(argc, argv);
KeyboardServo keyboard_servo;
signal(SIGINT, quit);
int rc = keyboard_servo.keyLoop();
input.shutdown();
rclcpp::shutdown();
return rc;
}
void KeyboardServo::spin()
{
while (rclcpp::ok())
{
rclcpp::spin_some(nh_);
}
}
int KeyboardServo::keyLoop()
{
char c;
bool publish_twist = false;
bool publish_joint = false;
std::thread{ this { return spin(); } }.detach();
puts("Reading from keyboard");
puts("---------------------------");
puts("All commands are in the planning frame");
puts("Use arrow keys and the '.' and ';' keys to Cartesian jog");
puts("Use 1|2|3|4|5|6|7 keys to joint jog. 'r' to reverse the direction of jogging.");
puts("Use 'j' to select joint jog. ");
puts("Use 't' to select twist ");
puts("Use 'w' and 'e' to switch between sending command in planning frame or end effector frame");
puts("'Q' to quit.");
for (;;)
{
// get the next event from the keyboard
try
{
input.readOne(&c);
}
catch (const std::runtime_error&)
{
perror("read():");
return -1;
}
}
return 0;
}
servo config yaml
A shot of the robot
moveit_config.zip
Beta Was this translation helpful? Give feedback.
All reactions