Easy question...? regarding Arduino to ROS

asked 2021-08-09 10:19:41 -0600

jang22 gravatar image

I made arduino code.ino to read two angles from the encoders(from one USB port) and want to send both data to read in ROS, below is my arduino code for sending data to ROS. Inorder to send data to ROS with Serial.write function, I made angle data into 2bytes form.

int16_t value1=0x0000;

int16_t value2=0x0000;

Serial.write((byte*) value1,2);

Serial.write("\n");

Serial.write((byte*) value2,2);

Serial.write("\n");

Now, i am having troble since I can't figure it out how to read these two data(2bytes each) in different functions from ROS (since they are not defined, they are just coming from arduino to ROS), so that i can publish two data separately. (My final goal is to publish two topics(each angles) and make one Subscriber to get the summation of two angle data)

I would be very very glad if anyone can give me new idea or solution to my problem. I am stuck at this point for half a day here....

edit retag flag offensive close merge delete

Comments

Where are you reading the data that is being written on the serial buffer by Serial.write()?

abhishek47 gravatar image abhishek47  ( 2021-08-09 23:27:56 -0600 )edit

I got my problem solved!

I read the data in ROS Publisher.py using ser.readline!

jang22 gravatar image jang22  ( 2021-08-10 05:24:26 -0600 )edit