How to communicate an arduino code with ROS? [closed]
Hi , I want to commicate this arduino code with ROS. How can I do this ? Please help me ?
#include <Wire.h>
#define MD22ADDRESS 0x58
#define SOFTREG 0x07
#define MOTOR1 0x01
#define ACCELLREG 0x03
signed long int pulse=0;
unsigned long last_time;
int ang=0;
int encoder_a=2;
int encoder_b=3;
float encoder_resolution=1024;
void setup()
{
Wire.begin();
delay(100);
Serial.begin(115200);
attachInterrupt(0,encoder_kesme_a,CHANGE);
last_time=millis();
setMode();
}
void loop()
{
delay(10);
Wire.beginTransmission(MD22ADDRESS);
Wire.write(MOTOR1);
Wire.write(220);
Wire.endTransmission();
if(millis()-last_time>1000)
{
ang=((pulse/encoder_resolution)*360.0);
ang=int(ang)%360;
Serial.println("Dc Motor Angle : " +String(ang));
last_time=millis();
}
}
void setMode(){
Wire.beginTransmission(MD22ADDRESS);
Wire.write(ACCELLREG);
Wire.write(0xFF);
Wire.endTransmission();
}
void encoder_kesme_a()
{
if (digitalRead(encoder_a) == HIGH)
{
if (digitalRead(encoder_b) == HIGH)
{
pulse++ ;
}
else
{
pulse = pulse - 1;
}
}
else
{
if (digitalRead(encoder_b) == HIGH)
{
pulse = pulse - 1;
}
else
{
pulse++;
}
}
}
Please add what you tried so far. Your post does not show any attempt of you to solve the task yourself. answers.ros is about helping, not doing it for you.
I converted 2d laserscan to 3d pointcloud and ı want to use dc motor with encoder to angle data instead of dynamixel servo motor . So ı wrote an arduino code that obtain an angle data. But I don't know how to communicate this code with the ROS. How to make the edits on this code.