ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

w.fradin's profile - activity

2019-03-05 14:56:50 -0500 marked best answer Publishing problem with gazebo using trajectory_msgs

Hi everyone,

I'm working on arm robotic, first, i wrote a physical model of the arm with a URDF files. This model work with Rviz and Gazebo. Moreover, i created a controllers.yaml file (for controls all robot's joints) and when I use the command : rostopic pub /arm_controller/command trajectory_msgs/JointTrajectory '{joint_names: ["hip","shoulder","elbow","wrist"], points: [{positions:[0.1,-0.5,0.5,0.75], time_from_start: [1.0,0.0]}]}' -1 both models (on rivz and gazebo) move simultaneously.

But now, I want to create a .cpp file for the arm to move independently by using trajectory_msgs::JointTrajectory. Here's my cpp file :

#include <ros/ros.h>
#include <trajectory_msgs/JointTrajectory.h>

ros::Publisher arm_pub;

int main(int argc, char** argv) {
ros::init(argc, argv, "state_publisher");
ros::NodeHandle n;
arm_pub = n.advertise<trajectory_msgs::JointTrajectory>("/arm_controller/command",1);

trajectory_msgs::JointTrajectory traj;

traj.header.stamp = ros::Time::now();
traj.header.frame_id = "base_link";
traj.joint_names.resize(4);
traj.points.resize(4);

traj.joint_names[0] ="hip";
traj.joint_names[1] ="shoulder";
traj.joint_names[2] ="elbow";
traj.joint_names[3] ="wrist";

while(ros::ok()){
   for(int i=0;i<4;i++) {
      int j = i%3;
      trajectory_msgs::JointTrajectoryPoint points_n;
      points_n.positions.push_back(j+0.1);
      points_n.positions.push_back(j+0.3);
      points_n.positions.push_back(j+0.3);
      points_n.positions.push_back(j);
      traj.points.push_back(points_n);
      traj.points[i].time_from_start = ros::Duration(1.0,0.0);
   }

  arm_pub.publish(traj);
  ros::spinOnce();
 }

return 0;
}

When i launch my file.launch and I rosrun my cpp file, both are connected on rqt_graph. But immediately, i have an error (on launch terminal) :

[ERROR] [1497596211.214814221, 9.889000000]: Trajectory message contains waypoints that are not strictly increasing in time.

Effectively, when i use the command rostopic echo /arm_controller/command, i have :

`positions: [0.0, 1.0, 0.0, 2.0]
 velocities: []
 accelerations: []
 effort: []
 time_from_start: 
  secs: 0
  nsecs: 0`

The time_from_start is always 0. So, I think i've a problem in my code but i don't know where.

Does anyone have an idea what is wrong? Thank you.

2018-10-17 04:33:00 -0500 received badge  Famous Question (source)
2018-03-12 20:35:06 -0500 received badge  Famous Question (source)
2018-01-18 08:32:01 -0500 received badge  Student (source)
2018-01-18 08:31:58 -0500 received badge  Self-Learner (source)
2018-01-18 08:31:58 -0500 received badge  Teacher (source)
2018-01-18 07:11:18 -0500 received badge  Famous Question (source)
2017-10-20 11:20:39 -0500 received badge  Notable Question (source)
2017-10-18 23:19:04 -0500 received badge  Famous Question (source)
2017-06-26 04:58:02 -0500 asked a question Question about urdf file and gazebo/msgs

Question about urdf file and gazebo/msgs Hi, I'm working on a robot arm, i already created a urdf and controller.yaml

2017-06-23 07:28:44 -0500 received badge  Popular Question (source)
2017-06-21 03:14:40 -0500 answered a question Publishing problem with gazebo using trajectory_msgs

I resolved my problem. Here is my first example that working and i explain it after : #include <ros/ros.h> #incl

2017-06-16 08:41:43 -0500 commented question Publishing problem with gazebo using trajectory_msgs

I understood that each trajectory point's time_from_start must be greater than the last. But I tried to increase this ti

2017-06-16 03:18:25 -0500 edited question Publishing problem with gazebo using trajectory_msgs

Publishing problem with gazebo using trajectory_msgs::JointTrajectory Hi everyone, I'm working on arm robotic, first,

2017-06-16 03:17:57 -0500 edited question Publishing problem with gazebo using trajectory_msgs

Publishing problem with gazebo using trajectory_msgs::JointTrajectory Hi everyone, I'm working on arm robotic, first,

2017-06-16 03:17:57 -0500 received badge  Editor (source)
2017-06-16 03:16:57 -0500 edited question Publishing problem with gazebo using trajectory_msgs

Publishing problem with gazebo using trajectory_msgs::JointTrajectory Hi everyone, I'm working on arm robotic, first,

2017-06-16 03:15:45 -0500 asked a question Publishing problem with gazebo using trajectory_msgs

Publishing problem with gazebo using trajectory_msgs::JointTrajectory Hi everyone, I'm working on arm robotic, first,

2017-05-20 15:32:57 -0500 received badge  Notable Question (source)
2017-05-20 15:32:57 -0500 received badge  Popular Question (source)
2017-05-06 22:07:49 -0500 received badge  Notable Question (source)
2017-04-24 10:28:56 -0500 received badge  Popular Question (source)
2017-04-24 10:23:44 -0500 marked best answer Why "#include <string>" doesn't work on rosserial?

Hi,

I work with ROS and Arduino and I want to include some libraries like #include <string> or #include <vector> to my rosserial program. When i compile, i have : fatal error: string: No such file or directory #include <string>.

I haven't find a solution. If someone can explain me how should i do.

Thank for your help.

William

2017-04-24 10:23:44 -0500 received badge  Scholar (source)
2017-04-24 08:03:36 -0500 asked a question Why "#include <string>" doesn't work on rosserial?

Why "#include <string>" doesn't work on rosserial? Hi, I work with ROS and Arduino and I want to include some li

2017-03-31 08:23:54 -0500 asked a question Best way to publish 3 coordinates (array, mat, vector...)?

Hi,

Since several days, I try to publish 3 coordinates to rosserial. Currently the only way I found, it's to publish this coordinates (x,y,z) in 3 differents topics. I would like to publish 1 vector/array or matrix (x,y,z) in one topic. I tried differents methods like :

http://answers.ros.org/question/22672...

http://answers.ros.org/question/23402...

But each time I had compilation problems. Or when there was no problem, my publisher and subscriber were not connected to each other (/rosrun rqt_graph rqt_graph).

Here's my program ;

#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <opencv/cv.h>
#include <std_msgs/Int16.h>
#include <vector>

namespace enc = sensor_msgs::image_encodings;
using namespace cv;
using namespace std;

static const char WINDOW[] = "Image Processed";

class ImageConverter
{
    ros::NodeHandle n;
    image_transport::ImageTransport it;
    image_transport::Publisher pub;
    image_transport::Subscriber sub;

    ros::Publisher x_pos = n.advertise<std_msgs::Int16>("position_x", 1000);
    ros::Publisher y_pos = n.advertise<std_msgs::Int16>("position_y", 1000);
    ros::Publisher z_pos = n.advertise<std_msgs::Int16>("position_z", 1000);
    std_msgs::Int16 pos_x;
    std_msgs::Int16 pos_y;
    std_msgs::Int16 pos_z;

public:

    ImageConverter()
        : it(n)
    {
// ...
    }

    ~ImageConverter()
    {
    cv::destroyWindow(WINDOW);
    }

    void imageCallback(const sensor_msgs::ImageConstPtr& msg)
    {
    // Initialization + OPENCV Transformation ... 

    if(contours.size() > 0){
        int radius(1);
        vector<Point2f>center( contours.size() );
        vector<float>radius_cur( contours.size() );

        // Get smallest circle enclosing contour.
        for(int i=0; i<contours.size();i++){
          // Finds the minimal enclosing of a 2D point.
          minEnclosingCircle(Mat(contours[i]),center[i], radius_cur[i]);
            if(radius_cur[i] > radius){
              radius = int(radius_cur[i]);
              x = center[i].x;
              y = center[i].y;
              target_pixel = radius_u*radius;
              // Depth of image
              z = (f_D)/target_pixel;
              // Draws a circle.
              circle(cv_ptr->image, center[i], radius, Scalar(0,0,255),2);
            }
              // 3 publications
              delta_step_x = sgn((centre_x-x))*min(abs((centre_x-x) / 50), 5);
              pos_x.data = delta_step_x;
              x_pos.publish(pos_x);

              delta_step_y = sgn((y-centre_y))*min(abs((y-centre_y) / 50), 5);
              pos_y.data = delta_step_y;
              y_pos.publish(pos_y);

              pos_z.data = z;
              z_pos.publish(pos_z);
            }
    }

    imshow(WINDOW, cv_ptr->image);
    waitKey(3);
    pub.publish(cv_ptr->toImageMsg());
    }
};

int main(int argc, char **argv)
{
    ros::init(argc, argv, "green_detection");
    ImageConverter bjr;
    ros::spin();
    return 0;
}

If someone can explain me and give me an example of how to proceed.

Thank for your help.

William

2017-03-27 09:37:09 -0500 received badge  Supporter (source)
2017-03-22 05:43:12 -0500 received badge  Notable Question (source)
2017-03-17 03:30:23 -0500 received badge  Enthusiast
2017-03-08 21:41:33 -0500 received badge  Popular Question (source)
2017-03-08 07:38:16 -0500 commented answer Tutorial "Writing a Simple Service and Client", i modified the wrong file, what can i do?

Thank a lot, problem solved !

2017-03-08 07:37:18 -0500 answered a question Tutorial "Writing a Simple Service and Client", i modified the wrong file, what can i do?

Thank a lot, problem solved !!

2017-03-08 07:22:56 -0500 asked a question Tutorial "Writing a Simple Service and Client", i modified the wrong file, what can i do?

Hey,

I wish to learn ros and I started by doing the tutorials available on ros.org .

But in the "Writing a Simple Service and Client" tutorial, when it say to modify the file ~/catkin_ws/src/beginner_tutorials/CMakeLists.txt. I modified the secure file that is in ~/catkin_ws/src using sudo gedit CMakeLists. Before that, it worked but now I have a mistake when I do catkin_make.

CMake Error at /opt/ros/kinetic/share/genmsg/cmake/genmsg-extras.cmake:94 (message): add_message_files() directory not found: /home/audensiel/catkin_ws/src/msg

Call Stack (most recent call first): CMakeLists.txt:9 (add_message_files)

-- Configuring incomplete, errors occurred! See also "/home/audensiel/catkin_ws/build/CMakeFiles/CMakeOutput.log". See also "/home/audensiel/catkin_ws/build/CMakeFiles/CMakeError.log". Invoking "cmake" failed

When I remove all files and folders and I restart at the beginning (the tutorials), and i created mkdir -p ~/catkin_ws/src ... The file I modified previously is always the same. I think this is my problem, so if someone can give me the contents of this file or tell me how to retrieve the original.

Thank for your help.

William

2017-03-08 07:22:55 -0500 asked a question Tuto "Writing a Simple Service and Client", I modified the wrong file CMakeFiles.txt what can i do?

Hey,

I wish to learn ros and I started by doing the tutorials available on ros.org .

But in the "Writing a Simple Service and Client" tutorial, when it say to modify the file "~ / catkin_ws / src / beginner_tutorials / CMakeLists.txt". I modified the secure file that is in "~/catkin_ws/src" using "sudo gedit CMakeLists". Before that, it worked but now I have a mistake when I do "catkin_make".

CMake Error at /opt/ros/kinetic/share/genmsg/cmake/genmsg-extras.cmake:94 (message): add_message_files() directory not found: /home/audensiel/catkin_ws/src/msg Call Stack (most recent call first): CMakeLists.txt:9 (add_message_files)

-- Configuring incomplete, errors occurred! See also "/home/audensiel/catkin_ws/build/CMakeFiles/CMakeOutput.log". See also "/home/audensiel/catkin_ws/build/CMakeFiles/CMakeError.log". Invoking "cmake" failed

When I remove all files and folders and I restart at the beginning (the tutorials), and i created "mkdir -p ~/catkin_ws/src" ... The file I modified previously is always the same. I think this is my problem, so if someone can give me the contents of this file or tell me how to retrieve the original.

Thank for your help.

William