Error while compiling "IrRanger" example

Hi all!

I'm facing a problem while compiling the rosserial IrRanger example that is provided in arduino.
Code as below;

#include <ros.h>
#include <ros/time.h>
#include <sensor_msgs/Range.h>

ros::NodeHandle nh;

sensor_msgs::Range range_msg;
ros::Publisher pub_range( "range_data", &range_msg);

const int analog_pin = 0;
unsigned long range_timer;

/*

  • getRange() - samples the analog input from the ranger
  • and converts it into meters.
    */
    float getRange(int pin_num){
    int sample;
    // Get data
    sample = analogRead(pin_num)/4;
    // if the ADC reading is too low,
    // then we are really far away from anything
    if(sample < 10)
    return 254; // max range
    // Magic numbers to get cm
    sample= 1309/(sample-3);
    return (sample - 1)/100; //convert to meters
    }

char frameid[] = "/ir_ranger";

void setup()
{
nh.initNode();
nh.advertise(pub_range);

range_msg.radiation_type = sensor_msgs::Range::INFRARED;
range_msg.header.frame_id = frameid;
range_msg.field_of_view = 0.01;
range_msg.min_range = 0.03;
range_msg.max_range = 0.4;

}

void loop()
{
// publish the range value every 50 milliseconds
// since it takes that long for the sensor to stabilize
if ( (millis()-range_timer) > 50){
range_msg.range = getRange(analog_pin);
range_msg.header.stamp = nh.now();
pub_range.publish(&range_msg);
range_timer = millis() + 50;
}
nh.spinOnce();
}

Error as below ;

In file included from /home/gerald/sketchbook/libraries/ros_lib/ros.h:39:0,
from IrRanger.cpp:7:
/home/gerald/sketchbook/libraries/ros_lib/ArduinoHardware.h:38:22: fatal error: WProgram.h: No such file or directory
compilation terminated.

Read this before posting a programming question

Point 2.

I tried before but is still display the same error

If you made the change successfully then it would not be looking for WProgram.h.
Where exactly did you make the change, which files and which directory ?