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

Fleurmond's profile - activity

2022-09-06 00:17:23 -0500 received badge  Nice Question (source)
2015-10-19 07:37:03 -0500 received badge  Famous Question (source)
2015-06-29 10:45:28 -0500 received badge  Notable Question (source)
2015-06-16 15:08:22 -0500 received badge  Student (source)
2015-06-16 15:05:55 -0500 received badge  Self-Learner (source)
2015-06-16 15:05:55 -0500 received badge  Teacher (source)
2015-06-16 09:50:59 -0500 commented answer Velocity control of PR2 arms and head

I checked on the real robot, the head falls down. I will look for the threshold. But I'm surprised to not be able to find other peoples with my problem.

2015-05-27 12:10:31 -0500 received badge  Popular Question (source)
2015-05-27 08:44:57 -0500 commented question ros::spin() can't work contione

Could I suggest you to check this two pages: This question: http://answers.ros.org/question/53055... make me think your could be a duplicate. And the theory http://wiki.ros.org/roscpp/Overview/C... .

2015-05-27 08:33:25 -0500 commented answer Velocity control of PR2 arms and head

I will check that, but its the same for the controller on the robot and in gazebo simulator ? I had the problems on simulation, I did not checked yet in the real robot.

2015-05-26 12:38:23 -0500 received badge  Editor (source)
2015-05-26 12:22:24 -0500 answered a question Subscribers blocking for performing calculations on data

Hi,

First I have the feeling that it would be helpful to you to re-read this tutorial:
http://wiki.ros.org/ROS/Tutorials/Wri...

Second, I would suggest you to check the name of the joints : http://docs.ros.org/api/sensor_msgs/h...

But I presume that you know well the robot that you are using, and you can ensure that the joint states will be published always in the same order !?

Then I have dared to rearrange your code in that way (it could be not the best one), but in purpose to avoid the use of global variables. I did not try to compile this code, but I reasonably hope it will work.

As a previous comment to your question said, ros::spin() or equivalent was missing. It's a kind of infinite loop, which check if no terminate signal is received and allow callback functions to be called when new data is available in subscribed topics.

I choose to publish whenever I receive data wherever he comes from, the measurements topic or the given order in topic /pid. I rename your two fonctions to avoid confusion with your variables.

#include "ros/ros.h"
#include "std_msgs/String.h"
#include "sensor_msgs/JointState.h"
#include <vector>
#include <sstream>
#define kp   1  //              P
#define ki   1  //              I
#define kd   1  //              D
#define dt 0.1  //              dt       

using namespace std;

class MyNicePID{

private:

  double previous_error;
  double integral;
  double setpoint;
  double measuredValue;
  double derivative;
  std::vector<double> vel;
  std::vector<double> pos;
  ros::Publisher chatter_pub; 
  ros::Subscriber sub_mes;
  ros::Subscriber sub_set;

public:

  MyNicePID(ros::NodeHandle n):
    previous_error(0.0),
    integral(0.0),
    setpoint(0.0),
    measuredValue(0.0),
    derivative(0.0),
    vel(2, 0.0),
    pos(2, 0.0)
  {
    chatter_pub = n.advertise<sensor_msgs::JointState>("/ptu/cmd", 1);
    sub_mes = n.subscribe("/joint_states", 1, &MyNicePID::measureCurrentVelocity,this);
    sub_set = n.subscribe("/pid",1,&MyNicePID::recordWantedVelocity,this);

  }

  void measureCurrentVelocity(const sensor_msgs::JointState::ConstPtr& msg)
  {      
    cout << "Measured value" << endl;
    measuredValue = msg->velocity[0];
    computeControlAndPublish();
  }
  void recordWantedVelocity(const sensor_msgs::JointState::ConstPtr& msg)
  {      
    //cout << "setPoint value" << endl;
    setpoint = msg->velocity[0];
    computeControlAndPublish();
  }

  void computeControlAndPublish()
  {

    double error = setpoint - measuredValue;
    integral = integral + error*dt;
    derivative = (error-previous_error)/dt;
    vel[0] = kp*error + ki*integral +kd*derivative;
    vel[1] = 0;
    previous_error = error;
    sensor_msgs::JointState msg;
    msg.position = pos;
    msg.velocity = vel;

    cout << vel[0] << endl;

    chatter_pub.publish(msg);

  }


};


int main(int argc, char **argv)
{

  ros::init(argc, argv, "pid");

  ros::NodeHandle node;

  MyNicePID johnSmith215(node);

  ros::spin();

  return 0;
}
2015-05-26 11:38:20 -0500 received badge  Supporter (source)
2015-05-26 11:27:20 -0500 answered a question Writing a simple CMakeLists.txt file for ROS

For what it's worth,

Could you try to install these packages:

ros-indigo-eigen-utils, ros-indigo-eigen-conversions

I'm using currently groovy and I don't have any experiences with indigo, but did you follow this tutorial ?

http://wiki.ros.org/ROS/Tutorials/Cre...

I would suggest you to follow all the tutorials for the beginner before writing any code.

http://wiki.ros.org/ROS/Tutorials

2015-05-26 11:13:06 -0500 commented question Which package should I use in CMakeLists.txt?

That could be true. But I think the title of both questions are really evasive. Then, it could be hard to find is someone already asked this question. And theirs problems look different.

2015-05-26 11:05:24 -0500 commented question ros::spin() can't work contione

I am asking a stupid question but did you check if fork is equal to zero with as basic printout as example ? What is the variable fork ? Is the code if (fork==0)inside a thread ?

2015-05-26 10:39:44 -0500 answered a question Velocity control of PR2 arms and head

I solved one part of the problem.

The main part is the periodicity of the control loop. I had to be sure that the control was sent to the robot in a suitable rate.

The computation time of the block for compute and send the command was evolving between 0.13 to 0.62 secs, but the time length of sent trajectory was really smaller around 0.05 secs

I optimized my code, mainly the most expensive functions, remove some weirds waiting calls. and the computation time drop down under 0.002 sec in ROS time on my computer. Then I could send easily control at 40 Hz.

But there still one problem, the head always fall down.

2015-05-22 07:37:42 -0500 asked a question Velocity control of PR2 arms and head

Hi all,

I'm trying to implement a visual servoing on PR2. I want to send joint velocities at some rate to the PR2 arms and the head.

After reading this tutorial Moving the arm using the joint trajectory action I computed an complete trajectory for joints of arms with around 800 waypoints (and provide velocity) with a period of 100 Hz, and send them to the robot in Gazebo simulation, it works almost perfectly [see bad video] ( https://www.youtube.com/watch?v=z8Ltc... ).

But when I compute periodically joints velocities and send them to the robot using the joint trajectory action with 1,2 or 3 way points, it seems to me that the arms follows the complete trajectory and stop at the last waypoint, whatever the given velocity.(and the visual servoing task is completed after 8 minutes instead of 13 seconds).

And also the head fall down to the front, while the next way point is computed to raise the head. I got all these results in Gazebo, with ROS Groovy on Ubuntu 12.04. ( I cannot upgrade the ROS neither the OS).

Is someone can point me the mistakes I possibly (probably) made, and suggest me a better way to implement the control, it would be really helpful.

Thank you in advance !

I can provide a more recent video if need, and please excuse the mistakes made by a french speaker.