How to use 'Timer' function to send ROS messages?

조회 수: 5 (최근 30일)
JAI PRAKASH
JAI PRAKASH 2018년 9월 7일
편집: Koundinya 2019년 2월 7일
fps=50;
How can send ROS messages through a publisher continuously.

채택된 답변

Koundinya
Koundinya 2018년 9월 10일
편집: Koundinya 2019년 2월 7일
You can use MATLAB timers in this way :
% Create a timer object
t=timer;
Set execution mode of the timer object to fixedRate, fixedDelay or fixedSpacing to execute your call back repeatedly
set(t,'executionMode','fixedRate');
Specify the function handle or the command you want to be executed. In your case, for sending messages over a ROS topic , use send :
set(t,'TimerFcn','send(pub,msg)');
Set the frequency or period(in seconds),at which the timer callback function is called
% To publish the message at a rate of 50 times per second
set(t,'Period', 0.02);
% Start the timer
start(t);
ROS message msg is then sent periodically(every 0.02 seconds). To stop the timer:
stop(t);
Delete the timer object after usage
delete(t);
  댓글 수: 5
Arun Prasanth Soungyan Gokul
Arun Prasanth Soungyan Gokul 2019년 2월 6일
Hi Koundinya,
I'm trying to use the timer object which you suggested. I already created the publisher and it's respective message(pub,msg). But when I set set(t,'TimerFcn','send(pub,msg)'), and the other attributes
and run start(t); it says undefined function or variable msg,undefined function or variable pub.
Can you please help me out from this?
Koundinya
Koundinya 2019년 2월 7일
편집: Koundinya 2019년 2월 7일
Hi Arun,
You need to first create a ROS publisher object(named 'pub' in this case) and then define a message ('msg') that is to be published. Take a look at the documentation of rospublisher and send for examples.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Publishers and Subscribers에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by