absolutely beginner: publisher and subscriber question

asked 2017-06-17 05:55:01 -0500

K03059164 gravatar image

updated 2017-06-19 10:41:13 -0500

I am an absolute beginner. I just try to send "/cmd_evl" msg to move robot while "/scan" msg is received. The received msg show me the distance between robot and target.

callbackFun(){ ......publish_.publish(msg_publish);......};

I am confused that why the received msg is discontinuous? I hope the received msg is like 20M->19M->18M->......0M? But It's received incorrect data suddenly mixed with correct data. ie: 20->19->5.3->2.7->18->17->......0.

A、 callbackFun(const sensor_msgs::LaserScan& msg) { ......

geometry_msgs::Twist twistMsg;

twistMsg.linear.x = msg.range[i] * cos(angle);

twistMsg.angular.z = msg.rangle[i] * sin(angle);

publisher_.publish(twistMsg);

.....

}

In this case, msg will be received incorrect data.

B、callbackFun(const sensor_msgs::LaserScan& msg)

{ ......

geometry_msgs::Twist twistMsg;

twistMsg.linear.x = msg.range[i] * cos(angle);

twistMsg.angular.z = msg.rangle[i] * sin(angle);

//publisher_.publish(twistMsg);

.....

}

In this case, msg will be received correct data. Of course 20->20->20......

C、 callbackFun(const sensor_msgs::LaserScan& msg) { ......

geometry_msgs::Twist twistMsg;

twistMsg.linear.x = 1;

twistMsg.angular.z = 1;

publisher_.publish(twistMsg);

.....

}

In this case, msg will be received correct data. Of course 20->19->18->19->20->19->18......

The correct msg format like:

  "**inf...20.111,23.11,24.111..inf**"  <<----first frame 
  "**inf...20.111,23.11,24.111..inf**"  <<---second frame
  "**inf...20.111,23.11,24.111..inf**"  <<---......
  "**inf...20.111,23.11,24.111..inf**"  <<---.....

The incorrect msg format like:

  "**inf...20.111,23.11,24.111..inf**"  <<----first frame
  "**...0.444,0.666,0.777,0.888,0.333.....**"  <<----second frame
  "**...0.444,0.666,0.777,0.888,0.333.....**"  <<----third frame
  "**...0.444,0.666,0.777,0.888,0.333.....**"  <<---fourth frame
  "**inf...20.111,23.11,24.111..inf**"  <<----......
  "**inf...20.111,23.11,24.111..inf**"  <<---.....
 "**...0.444,0.666,0.777,0.888,0.333.....**"<<---......

Though it can be solved through adding “if(...)”. I think it is an abnormal way.

My question:

A、Why?

B、whether it is a normal situation that has some exceptional data or not. Should I pay attention to something like frequency setting, sync time and so on?

Thanks a lot.

edit retag flag offensive close merge delete

Comments

1

Can you please try to describe what it is that you don't understand? Right now I'm having a hard time understanding your issue.

gvdhoorn gravatar image gvdhoorn  ( 2017-06-18 05:56:46 -0500 )edit

Thanks for your reply. I hope you understand this time. If you have any confusion, just let me know very soon, Waiting for your early reply, TKS again,

K03059164 gravatar image K03059164  ( 2017-06-18 08:12:51 -0500 )edit

"Waiting for your early reply," You get help for free...

NEngelhard gravatar image NEngelhard  ( 2017-06-19 02:19:52 -0500 )edit

I'm sorry but I also can not understand what you're trying to do or what you're asking. The question is worded confusingly.

Airuno2L gravatar image Airuno2L  ( 2017-06-19 06:45:49 -0500 )edit

@Airuno2L@gvdhoorn I subcribe the "/scan" topic and believe it will send me correct msg data. But actually it's not. So i am confused whether it's coused by my publish msg code or any bug......

K03059164 gravatar image K03059164  ( 2017-06-19 10:40:23 -0500 )edit

Is the /scan data coming from a lidar?

Airuno2L gravatar image Airuno2L  ( 2017-06-19 10:45:13 -0500 )edit

@Airuno2L No, just from the simulation.

K03059164 gravatar image K03059164  ( 2017-06-19 20:13:47 -0500 )edit

@NEngelhard Oops, I apologise for it. :)

K03059164 gravatar image K03059164  ( 2017-06-19 21:06:28 -0500 )edit