I want to control a servo attached to arduino by subscribing to /joint_states topic so that when the change the slider position the servo moves accordingly.
I tried with the following code but the servo doesn't change its position when i change the slider position on rviz.
The led on Arduino blinks as written in the callback function but the servo isn't moving.
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include
#endif
#include
#include
#include
#include
ros::NodeHandle nh;
Servo servo;
double ang=0;
void servo_cb( const sensor_msgs::JointState& cmd_msg){
ang=radiansToDegrees(cmd_msg.position[0]);
servo.write(ang); //set servo angle, should be from 0-180
digitalWrite(13, HIGH-digitalRead(13)); //toggle led
}
ros::Subscriber sub("joint_states", servo_cb);
void setup(){
pinMode(13, OUTPUT);
nh.getHardware()->setBaud(115200);
nh.initNode();
nh.subscribe(sub);
servo.attach(9); //attach it to pin 9
}
void loop(){
nh.spinOnce();
}
double radiansToDegrees(float position_radians)
{
position_radians = position_radians + 1.6;
return position_radians * 57.2958;
}
↧
Servo control arduino
↧
Arduino rosserial - Unable to sync with device
When I try to use the 'Hello World' program with rosserial and arduino after restarting my pc. The code works fine, however once i stop the serial communication and try to rerun the same code. I get the following error.
[INFO] [WallTime: 1399983521.604184] ROS Serial Python Node
[INFO] [WallTime: 1399983521.617853] Connecting to /dev/ttyACM0 at 57600 baud
[ERROR] [WallTime: 1399983538.726124] Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino
I am facing the same issue using both arduino UNO and arduino Nano. I have tried increasing the buffer size in ros.h, setting the baud rate in arduino code with Serial.begin(57600) and all the solutions mentioned in [link](https://answers.ros.org/question/210875/arduino-rosserial-unable-to-sync-with-device/). What else can i do to fix the problem ?
↧
↧
ROS Nodemcu Arduino compilation issue?
Hey guys , i am trying to run this https://github.com/agnunez/espros
I got an error like this when i tried to compile ,
'class ArduinoHardware' has no member named 'setConnection'
nh.getHardware()->setConnection(server, serverPort);
^
exit status 1
'class ArduinoHardware' has no member named 'setConnection'
Any one faced similar problems before ?
I am trying to run this on Ros-Indigo (Might that be the problem , should i try some newer version)
https://www.youtube.com/watch?v=o_gFGJNTh48 , this is what i am trying to do right now .
I can control the bot vai UDP packets generated from a python script .
But i would like to get it ROS enabled right from the MCU level .
I know i can write a middle ware python script to make it ROS enabled .(but i want a cleaner code)
↧
Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino
I am running ros kinetic and my rosserial works fine for all programs except one( in which i get above error).
I have tried all the techniques suggested but even then it doesnt work.( baudrate is fine , i tried to plugin usb a lot of times, rosserial works fine for other programs) but still i am getting the same error for only one program. What is the solution for this?
↧
Arduino subscriber not responding to Rosserial message
What would stop a subscriber on a Arduino, running rosserial, from responding to a message?
I have a subscriber on my Arduino defined as:
void on_pan_angle_set(const std_msgs::Int16& msg) {
pan_controller.set_target_angle(msg.data);
snprintf(buffer, 100, "Set pan angle: %d", msg.data);
nh.loginfo(buffer);
}
ros::Subscriber on_pan_angle_set_sub("pan_set", &on_pan_angle_set);
void setup() {
nh.getHardware()->setBaud(115200);
nh.initNode();
nh.subscribe(on_pan_angle_set_sub);
}
And after I launch my instance of `serial_node.py`, it outputs:
[INFO] [2018-05-07 10:54:36]: Setup subscriber on pan_set [std_msgs/Int16]
and running `rostopic list --verbose` shows:
Subscribed topics:
* /head_arduino/pan_set [std_msgs/Int16] 1 subscriber
However, when I try to publish a message on this topic with:
rostopic pub --once /head_arduino/pan_set std_msgs/Int16 120
nothing happens and the expected `"Set pan angle: 120"` text is not found in the serial_node's output or log, indicating it's not actually receiving the message. Why is this? What am I doing wrong?
↧
↧
publish error
i am doing a project of robot dicking station. This program is for three infrared receivers and three infrared emitters, i don't know why it happened. Could anybody help me ?
#include
#include
#include
#include
ros::NodeHandle nh;
std_msgs::String str_msg;
ros::Publisher st("state", &str_msg);
char state[10] = "cent-left";
char state_1[11] = "cent-right";
char state_2[10] = "cent-cent";
char state_3[11] = "right-left";
char state_4[12] = "right-right";
char state_5[11] = "right-cent";
char state_6[10] = "left-left";
char state_7[11] = "left-right";
char state_8[10] = "left-cent";
int RECV_PIN = 11;
int RECV_PIN_2= 9;
int RECV_PIN_1= 13;
IRrecv irrecv(RECV_PIN);
IRrecv irrecv1(RECV_PIN_1);
IRrecv irrecv2(RECV_PIN_2);
decode_results results;
void setup()
{
irrecv.enableIRIn();
irrecv1.enableIRIn();
irrecv2.enableIRIn();
nh.initNode();
nh.advertise(st);
}
void loop()
{
long Right=0xEF1F1509;
long left=0xCC36FF5E;
if (irrecv.decode(&results))
{
long val2= results.value;
if(val2==0xEF1F1509)
{
str_msg.data = state;
} else if(val2==0xCC36FF5E)
{
str_msg.data = state_1;
}
else {
str_msg.data = state_2;
}
st.publish( &str_msg );
}
if (irrecv1.decode(&results))
{
long val=results.value;
if (val==0xEF1F1509)
{
str_msg.data=state_3;
} else
if (val==0xCC36FF5E)
{
str_msg.data=state_4;
}else
{
str_msg.data=state_5;
}
st.publish(&str_msg);
}
if (irrecv2.decode(&results))
{
long val1=results.value;
if (val1==0xEF1F1509)
{
str_msg.data=state_6;
} else
if (val1==0xCC36FF5E)
{
str_msg.data=state_7;
}else
{
str_msg.data=state_8;
}
st.publish(&str_msg);
}
nh.spinOnce();
delay(1500);
}
Console:
[INFO] [WallTime: 1398132348.674181] ROS Serial Python Node
[INFO] [WallTime: 1398132348.682297] Connecting to /dev/ttyACM0 at 57600 baud
[ERROR] [WallTime: 1398132365.792995] Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino
↧
Not able to use frame_id from rosserial arduino in rviz
I am publishing a LaserScan Message from a teensy3.2 to a Raspberry Pi 3 running Kinetic, the scan is published via USB and received by the Pi Node.
When attempting to visualize just the scan in RViz I don't get any results. I have changed global options -> fixed frame to laser_frame as instructed by the wiki. However I still receive "No tf data. Actual error: Fixed frame [laser_frame] does not exist.
/Laser_scan
header:
seq: 13
stamp:
secs: 1455210523
nsecs: 855981927
frame_id: "laser_frame"
angle_min: 0.0
angle_max: 0.0
angle_increment: 0.0
time_increment: 0.0
scan_time: 0.0390000008047
range_min: 0.0500000007451
range_max: 1.20000004768
ranges: [0.12399999797344208, 0.12399999797344208, 0.12399999797344208, 0.12399999797344208, 0.12399999797344208, 0.12399999797344208, 0.12399999797344208, 0.12399999797344208, 0.12399999797344208, 0.12399999797344208]
intensities: []
When I run tf_monitor this is the result, no frames are shown.
$ rosrun tf tf_monitor
RESULTS: for all Frames
Frames:
All Broadcasters:
Any help would be appreciated I have been at this for sometime now, and to no avail.
↧
Arduino IDE can't find message header
Hey, I'm new to ROS and trying to have a led blink at will with my Arduino from my computer using a message, the future goal being to control several ones from my terminal. I am using ROS lunar and the rosserial_arduino package.
I wrote my publisher, subscriber and message, ran the package from a terminal to another as a test and it worked perfectly.
Then I put the subscriber code in a new Arduino sketch and adapted it. However, when I try to compile it, I get the following error:
/home/eric/Arduino/blink_one_ros/blink_one_ros.ino:2:30: fatal error: blink_one/Number.h: No such file or directory
#include
^
My include being as follows:
#include
#include
I already looked into [this answer](https://answers.ros.org/question/229511/how-to-use-custom-message-arduino-solved/) and several others, but I am afraid that it would be an error from my package so I want to be sure before re-installing ROS.
I did run the often advised:
rm -rf ros_lib/
rosrun rosserial_arduino make_libraries.py
And indeed, I can find my message header in my ros_lib/blink_one . Yet it still does not seem to be recognized.
If anyone knows a solution or has some hints, I'd appreciate it!
Thanks!
↧
Questions about spinOnce() and link problem with Arduino Due
Hi, I'm trying to build communication between my PC (ubuntu 16.04) and Arduino Due. I follow [rosserial tutorial](http://wiki.ros.org/rosserial_arduino/Tutorials) and run the "helloworld" example, then confused by two questions.
- Q1: After every effort to fix the error message "Unable to sync with device", it still comes up once though the link finally succeeded. I've added `#define _SAM3XA_` and `#define USE_USBCON` before `#define ` according to other discussion in the forum and the comments in [Arduinohardware.h](https://github.com/ros-drivers/rosserial/blob/jade-devel/rosserial_arduino/src/ros_lib/ArduinoHardware.h), and the baud rate is properly set to 9600 on both sides. The result seems to be fine: **it does work, but the error still occurs once (as shown below).** I think it could just be explained as the failure of requesting topic at first try, so it keeps trying and finally succeeds, but I'm still wondering how it happens.>ycchen@ubuntu:~$ rosrun rosserial_arduino serial_node.py _port:=/dev/ttyACM0 _baud:=9600
[INFO] [1528440034.212783]: ROS Serial Python Node
[INFO] [1528440034.215776]: Connecting to /dev/ttyACM0 at 9600 baud
[INFO] [1528440037.920751]: Requesting topics...
**[ERROR] [1528440052.922209]: Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino**
[INFO] [1528440052.922912]: Requesting topics...
[INFO] [1528440054.055047]: Note: publish buffer size is 512 bytes
[INFO] [1528440054.055647]: Setup publisher on chatter [std_msgs/String] - Q2: What's the function of spinOnce() in the sketch "helloworld"? My understanding is that spin() or spinOnce is associated with callback function, which is used by a subscriber, but in the "helloworld" case, only a publisher is created. Is it my misunderstanding of spin() and spinOnce()? Or the sketch is more complicated than just including a publisher? I appreciate every reply!!
[INFO] [1528440034.212783]: ROS Serial Python Node
[INFO] [1528440034.215776]: Connecting to /dev/ttyACM0 at 9600 baud
[INFO] [1528440037.920751]: Requesting topics...
**[ERROR] [1528440052.922209]: Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino**
[INFO] [1528440052.922912]: Requesting topics...
[INFO] [1528440054.055047]: Note: publish buffer size is 512 bytes
[INFO] [1528440054.055647]: Setup publisher on chatter [std_msgs/String] - Q2: What's the function of spinOnce() in the sketch "helloworld"? My understanding is that spin() or spinOnce is associated with callback function, which is used by a subscriber, but in the "helloworld" case, only a publisher is created. Is it my misunderstanding of spin() and spinOnce()? Or the sketch is more complicated than just including a publisher? I appreciate every reply!!
↧
↧
rosserial problem displaying linear_acceleration values from IMU
I have written a code for Arduino to connect with rosserial and publish on ros. However, it displays all the values correctly except linear_acceleration. I have changed the baud rate, call function from "vector.x()" to "vector[0]" and rechecked my sensor_msg/Imu.h file too. Everything looks correct. My Arduino code is as follows
#include
#include
#include
#include
#include
#include
#define BNO055_SAMPLERATE_DELAY_MS (10)
sensor_msgs::Imu odom_msg;
ros::Publisher pub_odom("imu0", &odom_msg);
ros::NodeHandle nh;
Adafruit_BNO055 bno = Adafruit_BNO055(10);
void setup(void)
{
nh.initNode();
nh.advertise(pub_odom);
Serial.begin(115200);
Serial.println(F("Orientation Sensor Test")); Serial.println(F(""));
/* Initialise the sensor */
if(!bno.begin())
{
/* There was a problem detecting the BNO055 ... check your connections */
Serial.print(F("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!"));
while(1);
}
delay(10);
}
void loop(void)
{
imu::Quaternion quat = bno.getQuat();
odom_msg.orientation.x = quat.x();
odom_msg.orientation.y = quat.y();
odom_msg.orientation.z = quat.z();
odom_msg.orientation.w = quat.w();
//odom_msg.orientation_covariance[0] = -1;
imu::Vector<3> angaccel = bno.getVector(Adafruit_BNO055::VECTOR_GYROSCOPE);
odom_msg.angular_velocity.x = angaccel[0];
odom_msg.angular_velocity.y = angaccel[1];
odom_msg.angular_velocity.z = angaccel[2];
imu::Vector<3> euler1 = bno.getVector(Adafruit_BNO055::VECTOR_LINEARACCEL);
odom_msg.linear_acceleration.x = euler1[0];
odom_msg.linear_acceleration.y = euler1[1];
odom_msg.linear_acceleration.z = euler1[2];
//odom_msg.linear_acceleration.x = euler1.x();
//odom_msg.linear_acceleration.y = euler1.y();
//odom_msg.linear_acceleration.z = euler1.z();
odom_msg.angular_velocity_covariance[0] = 0;
odom_msg.linear_acceleration_covariance[0] = 0;
odom_msg.header.frame_id = "imu";
odom_msg.header.stamp = nh.now();
pub_odom.publish(&odom_msg);
nh.spinOnce();
delay(BNO055_SAMPLERATE_DELAY_MS);
}
**On Arduino serial monitor with a similar code, i am able to get all values correctly. But not on rosserial. The ourput on rosserial is the following**
---
header:
seq: 311
stamp:
secs: 1531067114
nsecs: 53815114
frame_id: imu
orientation:
x: -0.0120849609375
y: -0.0156860351562
z: 0.0182495117188
w: 0.999633789062
orientation_covariance: [0.0, 0.0, 0.0, 605297.1875, 9.805493222936335e-12, 6.358072525405582e-30, -8.836671222230488e-18, 6.8332662107650395e-34, 7.80629698470661e-36]
angular_velocity:
x: -0.00111111113802
y: -0.00111111113802
z: 0.00222222227603
angular_velocity_covariance: [0.0, 2.375406719749005e-36, -37636.5, -601862893993984.0, -37759.015625, 3.8772519442846755e-34, 2.6677259486100874e-23, 3.56086808692405e-310, 4.425906002008659e-23]
linear_acceleration:
x: 1.26991024075e-33
y: 6.96170055628e-309
z: 8.84134401092e-36
linear_acceleration_covariance: [9.091709527866322e-34, 4.673124563523994e+16, 1.9121903536199017e-308, 1.956152820753018e-38, -0.0004948825226165354, -1.010046607868369e+22, -5.629338932247528e+25, -4.8146399716934285e-28, 0.019999999552965164]
---
I am not worried about the covariance values, as i dont require them, but the linear_acceleration values don't change with time, even under a lot of moment of imu. In the code, I even tried to set the value of published linear_acceleration to 0 but still shows that constant value.
Please help me, if anyone is able to figure out my mistake.
↧
Publishing to a topic from Arduino in a class
Hello All,
I have to publish status messages (boolean) from an Arduino board using rosserial.
I am able to do it when I make them independently, but facing problem, when I am putting the publisher in a *class*.
Can somebody please give a reference of publishing on a topic in a class from Arduino.
Saurabh
↧
Arduino rosserial not updating (not in-sync) with ROS movements
Hello,
I am trying to make a 3 link robot arm (with 3 steppers) move in a single plane. I am facing some problems when interfacing it with my Arduino Uno.
The robot -arm moves, but sometimes it goes out of sync and it does not move to it's final position for the corresponding movement in ROS. I have debugged the issue and these are the prints from ROS publisher.
[ INFO] [1543985383.681003214]: total: 1845
[ INFO] [1543985383.681053201]: Done conversion to /joint_steps
[ INFO] [1543985383.681491597]: total: 1430
[ INFO] [1543985383.681544521]: Done conversion to /joint_steps
[ INFO] [1543985383.886151296]: total: 1080
[ INFO] [1543985383.886732527]: Done conversion to /joint_steps
[ INFO] [1543985383.892410070]: total: 781
[ INFO] [1543985383.894085465]: Done conversion to /joint_steps
[ INFO] [1543985384.080022691]: Published to /joint_steps
[ INFO] [1543985384.080923482]: total: 511
[ INFO] [1543985384.080969519]: Done conversion to /joint_steps
[ INFO] [1543985384.081409690]: total: 381
[ INFO] [1543985384.081448439]: Done conversion to /joint_steps
[ INFO] [1543985384.280018187]: Published to /joint_steps
[ INFO] [1543985384.281263874]: total: 271
[ INFO] [1543985384.281349498]: Done conversion to /joint_steps
[ INFO] [1543985384.282131103]: total: 161
[ INFO] [1543985384.282210489]: Done conversion to /joint_steps
[ INFO] [1543985384.480194118]: Published to /joint_steps
[ INFO] [1543985384.481680640]: total: 51
[ INFO] [1543985384.481775764]: Done conversion to /joint_steps
[ INFO] [1543985384.482577219]: total: 3
[ INFO] [1543985384.482759154]: Done conversion to /joint_steps
The final position should be 3 , but looking at the message published from the arduino, the final value is 1430.
data: 9537
---
data: 9426
---
data: 9206
---
data: 8875
---
data: 8260
---
data: 6439
---
data: 1430
---
Is this a possible problem of the arduino not able to receive all the messages on time? My ros piblisher works at 10Hz(max) and my arduino loop at 50Hz.
↧
Sending arrays (LaserScan msg) in rosserial
Hi, I'm trying to send data from a temperature sensor using the intensities array within a LaserScan message (this will then be manipulated within ROS further. using laserScan does make sense later down the road).
The sensor gives out an array of 64 numbers, I extract the ones I want and put them into another array, this array is then assigned to the intensities field of the message.
However, when I try to compile the code I get the error:
exit status 1
cannot convert 'float' to 'sensor_msgs::LaserScan::_intensities_type* {aka float*}' in assignment
Code:
#include
#include
#include
#include
#include
//***ROS requrments***//
ros::NodeHandle nh;
sensor_msgs::LaserScan Temp_distance;
ros::Publisher pub_dis("AMG833", &Temp_distance);
const float angle = 60;
float minimum_angle = 0 - (((angle * 71) / 4068) / 2);
float max_angle = (((angle * 71) / 4068) / 2);
float inc = (((angle * 71) / 4068)/8);
char frameid[] = "/AMG833id";
//***AMG8833 requrments***//
Adafruit_AMG88xx amg;
float pixels[AMG88xx_PIXEL_ARRAY_SIZE];
float middle[7];
void setup()
{
//***ROS requrments***//
nh.initNode();
nh.advertise(pub_dis);
//***AMG8833 requrments***//
delay(100); //sensor boot
}
void loop()
{
//read all the pixels
amg.readPixels(pixels);
for (int i = 0; i <=7; i++)
{
int pixelval = 32-i;
middle[i] = pixels[pixelval];
}
Temp_distance.angle_min = minimum_angle;
Temp_distance.angle_max = max_angle;
Temp_distance.intensities = middle[7];
Temp_distance.header.frame_id = frameid;
Temp_distance.header.stamp = nh.now();
Temp_distance.angle_increment = inc;
Temp_distance.scan_time = 0.1;
pub_dis.publish( &Temp_distance );
nh.spinOnce();
delay(1000);
}
Sorry if i've got the formatting of the post wrong, (feel free to fix if necessary mods)
↧
↧
Unable to sync with device rosserial_python
i got this error
[ERROR] [1544705194.347108]: Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino
↧
Roslocate shows wrong package version - how do I install the right one?
I've just installed ROS Kinetic from source on my Raspberry Pi (running Raspbian Stretch), and I'd like to add rosserial and rosserial_arduino. When I looked up the packages with roslocate, I got this:
pi@raspberrypi:~/ros_catkin_ws $ roslocate info rosserial
Using ROS_DISTRO: kinetic
- git:
local-name: rosserial
uri: https://github.com/ros-drivers/rosserial.git
version: jade-devel
pi@raspberrypi:~/ros_catkin_ws $ roslocate info rosserial_arduino
Using ROS_DISTRO: kinetic
- git:
local-name: rosserial_arduino
uri: https://github.com/ros-drivers/rosserial.git
version: jade-devel
I haven't generated a rosinstall including these yet, because I'm worried about those version descriptions. Is it nothing to worry about, or do I have to do something special to get the Kinetic versions rather than the Jade ones?
↧
Unable to subscribe to string topic using rosserial arduino nano
I am working with arduino nano to subscribe to a topic which reads keystrokes(Raspberry pi ubuntu mate melodic) and publishes into onto the topic.I am trying subscribe to the topic on an arduino which then prints the value onto the serial monitor. The output on the serial monitor is not consistent its printing random values onto to screen. The terminal is also showing a few errors which I am not able to decipher.
This is my code
#include
#include
ros::NodeHandle_ nh;
void comCallback( const std_msgs::String& command)
{
if (command.data == "q")
{
Serial.println(command.data);
}
}
ros::Subscriber sub("/ignis/move", comCallback);
void setup(){
nh.initNode();
nh.subscribe(sub);
}
void loop(){
nh.spinOnce();
delay(10);
}
These are the errors that popup on the terminal for rosrun rosserial_python serial_node.py
[WARN] [1550492941.390503]: Serial Port read failure: device reports readiness to read but returned no data (device disconnected or multiple access on port?)
[INFO] [1550492941.498101]: wrong checksum for msg length, length 76
[INFO] [1550492941.502178]: chk is 1
[WARN] [1550492942.992464]: Serial Port read failure: device reports readiness to read but returned no data (device disconnected or multiple access on port?)
[ERROR] [1550492943.095225]: Mismatched protocol version in packet: lost sync or rosserial_python is from different ros release than the rosserial clien
↧
Publishing odometry with rosserial
Hello, i am working with an Arduino Mega and a RPI using the rosserial, and i have a couple of doubts. I am working with a differential robot and i am using the Arduino for controlling the motors (i have a subscriber node), and now i need to publish the odometry information back to ROS (my intention is to use the Navigation stack in the future), but i am having a few problems with this. In the first place, i don't know how to create de odometry message (i read the following posts [link text](http://wiki.ros.org/navigation/Tutorials/RobotSetup/Odom) and [link text](https://answers.ros.org/question/241118/odometry-message-from-arduino/) but i still don't know understand this). In second place, once i have create the odometry message, i want to publish it to ros like in this example [link text](http://wiki.ros.org/rosserial_arduino/Tutorials/Hello%20World). Is my code correct for doing this? (only see the publishing parts, the others work well)
Here is the full code
#include #include #include #include "DualVNH5019MotorShield.h" #include #include
const byte pinEnc1a = 21; const byte pinEnc2a = 18; const byte pinEnc1b = 20; const byte pinEnc2b = 19;
int Direc; volatile long paso1=0; volatile long paso2=0; unsigned long ta1, tb1, ta2, tb2, dT1, dT2;
int aux=0;
float R = 0.035; // Radio ruedas
float L = 0.24; // Longitud entre ruedas
volatile float v=0;
volatile float w=0;
double Vr, Vl =0;
double Input1, Output1;
double Input2, Output2;
double Kp=.5;
double Ki=0.3;
double Kd=0;
PID myPID1(&Input1, &Output1, &Vr, Kp, Ki, Kd, DIRECT);
PID myPID2(&Input2, &Output2, &Vl, Kp, Ki, Kd, DIRECT);
DualVNH5019MotorShield md;
ros::NodeHandle nh;
v = mensaje_motor.linear.x;
w = mensaje_motor.angular.z;
Vl = v + (w*L)/2;
Vr = v - (w*L)/2;
if (v==0 && w==0){
aux=1;
md.setM1Speed(0);
md.setM2Speed(0);
while(aux==1){
if (v!=0 || w!=0){
Input1=0;
Input2=0;
ta1=ta2=0;
aux=0;
}
nh.spinOnce();
}
}
}
nav_msgs::Odometry odom;
ros::Publisher odometria ("nav_msgs::Odometry", &odom);
ros::Subscriber sub("cmd_vel", &Cbmotor );
void setup()
{
pinMode(pinEnc1a, INPUT);
attachInterrupt(digitalPinToInterrupt(pinEnc1a), interrupcion1, FALLING);
pinMode(pinEnc2a, INPUT);
attachInterrupt(digitalPinToInterrupt(pinEnc2a), interrupcion2, FALLING);
pinMode(pinEnc1b, INPUT);
pinMode(pinEnc2b, INPUT);
Output1 = 0;
Output2 = 0;
md.init();
myPID1.SetMode(AUTOMATIC);
myPID2.SetMode(AUTOMATIC);
myPID1.SetOutputLimits(-50,50 );
myPID2.SetOutputLimits(-50,50 );
md.setM1Speed(0);
md.setM2Speed(0);
ta1=ta2=micros();
nh.initNode();
nh.subscribe(sub);
md.init();
Serial.begin(57600);
nh.advertise(odometria);
}
void loop()
{
myPID1.Compute();
md.setM1Speed(-(Vr+Output1));
myPID2.Compute();
md.setM2Speed(Vl+Output2);
odometria.publish(&odom);
nh.spinOnce();
}
void interrupcion1()
{
paso1++;
if (paso1%(70*16/6)==0)
{
tb1 = micros();
if (ta1!=0) {
dT1 = tb1-ta1;
Input1= (60000000UL*400)/(dT1*90);
if (Vr<0) {
Input1= -Input1;;
}
}
ta1=tb1;
}
}
void interrupcion2()
{
paso2++;
if (paso2%(70*16/6)==0)
{
tb2 = micros();
if (ta2!=0) {
dT2 = tb2-ta2;
Input2= (60000000UL*400)/(dT2*90);
if (Vl<0) {
Input2= -Input2;
}
}
ta2=tb2;
}
}
Sorry for my english, but i am from Argentina. Thanks for your help.
↧
↧
How to calculate the force created by the servo motor using the rosserial_arduino library
I'm using a servo motor to build a braking system inside the bicycle and I want to measure the braking force that will be delivered by the servo motor to the wheels in order to control the braking system.
↧
How to integrate rosserial_arduino in an existing sketch?
I made code in just arduino. but i wanna change it to rosserial_arduino code. but i don't know how to do.....
#include
SoftwareSerial hc06(10,11); //Tx, Rx
int total_state = 0;
int switch_on = 0;
int switch_rev = 0;
int switch_on_state = 0;
int switch_rev_state = 0;
int switch_on_pin = 3;
int switch_rev_pin = 4;
double emg ;
//double temp_max = 27;
double emg_max = 200;
double pres;
double pres_max = 150;
int mydelay = 300;
int relay_motor_pin = 9;
int pow_led_pin = 12;
int rev_led_pin = 13;
int baby_mot_pin = 6;
int direct_pin = 7;
unsigned long currentMillis;
unsigned long previousMillis = 0;
unsigned long changetime = 0;
//////////////////////
void pumpon(int relay_motor_pin) {
digitalWrite(relay_motor_pin, HIGH);
}
void pumpoff(int relay_motor_pin) {
digitalWrite(relay_motor_pin, LOW);
}
void pumprev(int LED_REV) {
digitalWrite(direct_pin,LOW);
analogWrite(baby_mot_pin,255);
delay(3000);
analogWrite(baby_mot_pin,0)
;
}
void serial_comu(int MYDELAY, double EMG, double PRES, int TOTAL_STATE, int SWITCH_ON_STATE) {
currentMillis = millis();
if (currentMillis - previousMillis > MYDELAY) {
hc06.print("= EMG = ");
hc06.print(EMG);
hc06.print("= PRES = ");
hc06.print(PRES);
hc06.print("= total state = ");
hc06.print(TOTAL_STATE);
hc06.print("= switch on state=");
hc06.print(SWITCH_ON_STATE);
hc06.println(" ");
previousMillis = currentMillis;
}
}
////////////////////////////////
void setup() {
Serial.begin(9600);
pinMode(relay_motor_pin, OUTPUT);
pinMode(switch_on_pin, INPUT);
pinMode(switch_rev_pin, INPUT);
pinMode(pow_led_pin,OUTPUT);
pinMode(rev_led_pin,OUTPUT);
pinMode(baby_mot_pin,OUTPUT);
pinMode(direct_pin,OUTPUT);
Serial.println("Enter AT commands:");
hc06.begin(9600);
}
void loop() {
if(hc06.available()){
Serial.write(hc06.read());
}
if(Serial.available()){
hc06.write(Serial.read());
}
emg = analogRead(A0);
pres = analogRead(A1);
switch_on = digitalRead(switch_on_pin);
switch_rev = digitalRead(switch_rev_pin);
if ( (millis() - changetime > 1000) && switch_on_state == LOW && switch_on == HIGH) {
switch_on_state = HIGH;
digitalWrite(pow_led_pin,HIGH);
changetime = millis();
}
if ( (millis() - changetime > 1000) && switch_on_state == HIGH && switch_on == HIGH) {
switch_on_state = LOW;
digitalWrite(pow_led_pin,LOW); //???????????????
changetime = millis();
}
if ( (millis() - changetime > 1000) && switch_rev_state == LOW && switch_rev == HIGH) {
switch_rev_state = HIGH;
digitalWrite(rev_led_pin,HIGH);
changetime = millis();
}
if ( (millis() - changetime > 1000) && switch_rev_state == HIGH && switch_rev == HIGH) {
switch_rev_state = LOW;
changetime = millis();
}
if ( (switch_on_state == HIGH) && (emg >= emg_max) && (pres <= pres_max) ) {
total_state = 1;
}
if (total_state == 1) {
pumpon(relay_motor_pin);
}
if ( (switch_on_state == LOW) || (pres > pres_max) ) {
total_state = 0;
}
if (total_state == 0) {
pumpoff(relay_motor_pin);
}
if (switch_rev_state == HIGH) {
total_state = 2;
}
if (total_state == 2) {
pumprev(relay_motor_pin);
digitalWrite(rev_led_pin,LOW);
total_state = 0;
switch_rev_state = LOW;
}
serial_comu(mydelay, emg, pres, total_state, switch_on_state);
}
↧