Blinking LED using ROS on Odroid-C1 and Raspberry Pi 2

This is a basic LED example which can blink the LED connected to the first pin of Wiring Pi, that is the 12th pin on the board. The LED cathode is connected to the GND pin and 12th pin as an anode.

The following image shows the circuit of Raspberry Pi with an LED. The same pin out can be used in Odroid too.

Figure 25 : Blinking an LED using Raspberry Pi 2

We can create the example ROS package using the following command:

    $ catkin_create_pkg ros_wiring_example roscpp std_msgs

You will get the existing package from the chapter_7_codes/ROS_Odroid_Examples/ ros_wiring_examples folder.

Create a src folder and create the following code called blink.cpp inside the
src folder:

#include "ros/ros.h" 
#include "std_msgs/Bool.h" 
#include <iostream> 
 
//Wiring Pi header 
#include "wiringPi.h" 
 
//Wiring PI first pin 
 
#define LED 1 
 
//Callback to blink the LED according to the topic value 
void blink_callback(const std_msgs::Bool::ConstPtr& msg) 
{ 
 
 if(msg->data == 1){ 
  digitalWrite (LED, HIGH) ;  
  ROS_INFO("LED ON"); 
  } 
 if(msg->data == 0){ 
   digitalWrite (LED, LOW) ;  
  ROS_INFO("LED OFF"); 
    } 
} 
int main(int argc, char** argv) 
{ 
  ros::init(argc, argv,"blink_led"); 
  ROS_INFO("Started Odroid-C1 Blink Node"); 
   //Setting WiringPi 
  wiringPiSetup ();
//Setting LED pin as output pinMode(LED, OUTPUT); ros::NodeHandle n; ros::Subscriber sub = n.subscribe("led_blink",10,blink_callback); ros::spin(); }

This code will subscribe a topic called led_blink, which is a Boolean type. If we publish 1 to this topic, it will switch on the LED. If we publish 0, the LED will turn off.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.193.158