ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

linear motion very basic algorithm doesn't work

asked 2018-09-20 05:24:34 -0500

edamondo gravatar image

Hi,

I am controlling a linear robot with it's acceleration. I wan't to go from a point p1 to the point p2, using the maximum acceleration I have which I call "a". With this acceleration, I can know how much time it takes to go from p1 to p2 ( time = sqrt((p2-p1)/a). So I wrote this :

    void My_package::accelerate(double a, double t)                                                                                                                  
     {                                                                                                                                                                
             geometry_msgs::Vector3 acc_cmd;                                                                                                                          

             ros::Duration delta_t = ros::Duration(t/2);                                                                                                              


            ros::Time beginTime = ros::Time::now();
            ros::Time t1 = beginTime + delta_t;                                                                                                                      
            ros::Time t2 = t1 + delta_t;                                                                                                                             
           //change the acceleration command.                                                                                                                       





          while(ros::Time::now() < t1)                                                                                                                                
          {                                                                                                                                                                                                                        
             acc_cmd.x = 0;                                                                                                                                   
             acc_cmd.y = a;                                                                                                                                   
             pub_acc_cmd_.publish(acc_cmd);                                                                                                                   
           }                                                                                                                                                        
          while((ros::Time::now() < t2) && (ros::Time::now() >= t1))                                                                                               
         {                                                                                                                                                        
                 acc_cmd.x = 0;                                                                                                                                   
                 acc_cmd.y = -a;                                                                                                                                  
                 pub_acc_cmd_.publish(acc_cmd);                                                                                                                   
         }                                                                                                                                                        

  }

But unfortunately this result in moving up and then mooving too much down and continue having much speed at the end.

How can I solve this problem?

Thank you for your help!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-09-20 05:54:34 -0500

Exactly what type of actuator are you controlling? This information will help us understand your problem.

However I can see a problem with your approach. You're publishing acceleration command messages as fast as the computer is able to not at a fixed rate. This is probably resulting in message buffers filling up and overflowing.

You cannot assume that because you publish acceleration commands for a fixed amount of time, they will be received for that same fixed amount of time, due to buffering problems amongst others. This is probably the cause of your problem.

If you use a ros::Rate object to set the rate of your two while loops to something sensible such as 100 Hz. This may help alleviate the problem but reaching point p2 will probably still be a challenge.

If there is position feedback on your actuator a closed loop solution would probably be a much better way to go.

You probably also want to look into Trapezoidal velocity control because there may be a maximum velocity that has to be adhered to as well.

Hope this helps.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2018-09-20 05:24:34 -0500

Seen: 87 times

Last updated: Sep 20 '18