Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
1 views

ROS interface with Arduino Sensor Actuator 2-4

The document outlines the process of interfacing a DHT11 temperature and humidity sensor with an Arduino and ROS for monitoring environmental conditions. It details hardware connections, launching ROS nodes, and data exchange between Arduino and ROS, as well as providing code examples for both Arduino and a Python ROS package for controlling a rover. The primary goal is to enable temperature and humidity data collection and control of a rover's movement in a rectangular path using ROS commands.

Uploaded by

Mehwish Aleem
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

ROS interface with Arduino Sensor Actuator 2-4

The document outlines the process of interfacing a DHT11 temperature and humidity sensor with an Arduino and ROS for monitoring environmental conditions. It details hardware connections, launching ROS nodes, and data exchange between Arduino and ROS, as well as providing code examples for both Arduino and a Python ROS package for controlling a rover. The primary goal is to enable temperature and humidity data collection and control of a rover's movement in a rectangular path using ROS commands.

Uploaded by

Mehwish Aleem
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

ROS interfacing with Arduino, Sensor and Actuator

BLOCK DIAGRAM FOR INTERFACING SENSOR WITH ARDUINO AND


ROS:
The DHT11's temperature range of 0°C to 50°C (32°F to 122°F) is well-suited for
indoor environments, which are typically encountered in commercial entities.
While the sensor's accuracy of approximately ±2°C may not be as precise as more
advanced temperature sensors, it remains sufficient for our application, as the
primary goal is to monitor general temperature trends rather than requiring
precise measurements.

ARDUINO CONNECTIVITY WITH DHT-11 SENSOR:

The DHT-11 (also named as AM2302) is a digital-output relative humidity and


temperature sensor. It uses a capacitive humidity sensor and a thermistor to
measure the surrounding air, and spits out a digital signal on the data pin.

1. Hardware Connections:
Connected the VCC pin of the DHT11 to the 5V pin on the Arduino.

Connected the GND pin of the DHT11 to the GND pin on the Arduino.
Connected the DATA pin of the DHT11 to a digital pin 2 on the Arduino.

2. Launching ROS Nodes:

Launch the necessary ROS nodes, including the subscriber node and any other nodes required.
Arduino is connected to laptop, and the ROS serial node is running to establish communication
between the Arduino and ROS.

3. Data Exchange:
Once the Arduino and ROS are successfully connected, the sensor data will be published by the
Arduino and received by the subscriber node in ROS. Now, temperature and humidity data in
ROS can be accessed and used for further processing, visualization, or control of our robot
system.

ON HOST SIDE (ROS NODE) :


2) The commands run on LINUX Terminal for creating a ROS Master by running command
“roscore”
3) After running the above command, type “rosrun rosserial_python serial_node.py
/dev/ttyUSB0” The file serial_node.py is run from the ros package rosserial_python. The port
that is being used is ttyUSB0.

4) To subscribe to the topic “Temperature”, use the command “rostopic echo temperature”

a rospackage can also be created to predefine the movement of rover. Firstly a ros package is created in
~/home/catkin_ws/src by the following command using catkin workspace:
catkin_create_pkg car_control rospy geometry_msgs

Now create a python file in the src directory of car_control. This file contains the necessary instructions
to ensure that the rover moves in a rectangular path each time the file is executed.

The execution of the created package can be demonstrated as follows.

a) Use the catkin_make command in catkin_ws/

b) Set up the environment using the following command

Source devel/setup.bash

c) Run the package using rosrun


Rosrun car_control car_control.

CODE FOR ARDUINO:

#include "DHT.h"

#include <ros.h>

#include <sensor_msgs/Temperature.h>

#include <sensor_msgs/RelativeHumidity.h>

#include <SoftwareSerial.h>

#include <geometry_msgs/Twist.h>

#define DHTPIN 2 // what pin we're connected to

#define DHTTYPE DHT11 // DHT 22 (AM2302)

DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino

#define IN1 9

#define IN2 8

#define IN3 7
#define IN4 6

ros::NodeHandle node;

sensor_msgs::Temperature temp_msg;

sensor_msgs::RelativeHumidity humidity_msg;

ros::Publisher pub_temp("temperature", &temp_msg);

ros::Publisher pub_humidity("humidity", &humidity_msg);

geometry_msgs::Twist msg;

void forward()

digitalWrite(IN1, HIGH);

digitalWrite(IN2, LOW);

digitalWrite(IN3, HIGH);

digitalWrite(IN4, LOW);

void stop()

digitalWrite(IN1, LOW);

digitalWrite(IN2, LOW);

digitalWrite(IN3, LOW);

digitalWrite(IN4, LOW);

void roverCallBack(const geometry_msgs::Twist& cmd_vel)

if (cmd_vel.linear.x > 0 && cmd_vel.angular.z == 0)

forward(); //i
analogWrite(test, 255);

else

if (cmd_vel.linear.x == 0 && cmd_vel.angular.z == 0)

stop(); //k

analogWrite(test, 0);

ros::Subscriber <geometry_msgs::Twist> sub("cmd_vel", roverCallBack);

void setup()

node.initNode();

node.advertise(pub_temp);

node.advertise(pub_humidity);

dht.begin();

node.initNode();

node.subscribe(sub);

pinMode(test, OUTPUT);

pinMode(IN1, OUTPUT);

pinMode(IN2, OUTPUT);

pinMode(IN3, OUTPUT);

pinMode(IN4, OUTPUT);

}
void loop()

begn:delay(1000);

//Read data and store it to variables hum and temp

humidity_msg.relative_humidity = dht.readHumidity();

temp_msg.temperature = dht.readTemperature();

temp_msg.header.stamp = node.now();

humidity_msg.header.stamp = node.now();

//Print temp and humidity values to serial monitor

pub_temp.publish( &temp_msg );

pub_humidity.publish( &humidity_msg );

digitalWrite(test, LOW);

node.spinOnce();

CODE FOR PYTHON FILE FOR CAR_CONTROLL PACKAGE IN ROS:

#!/usr/bin/env python3

import rospy

from geometry_msgs.msg import Twist

def move_rectangular():

rospy.init_node('car_control_node', anonymous=True)

pub = rospy.Publisher('/cmd_vel', Twist, queue_size=10)

rate = rospy.Rate(10) # 10Hz

# Move forward

twist_msg = Twist()

twist_msg.linear.x = 0.2 # Adjust the linear speed as needed


twist_msg.angular.z = 0.0

pub.publish(twist_msg)

rospy.sleep(3.0) # Adjust the duration as needed

# Stop

twist_msg.linear.x = 0.0

pub.publish(twist_msg)

rospy.sleep(2.0)

if _name_ == '_main_':

try:

move_rectangular()

except rospy.ROSInterruptException:

pass

You might also like