Ask Your Question
0

Problem with IR Sensor

asked 2014-09-15 10:51:51 -0600

nadal11 gravatar image

updated 2014-10-14 05:07:31 -0600

Hi everybody,

I have a problem here. I try to control the turtlebot speed based on the IR sensors reading. Unfortunately, the turtlebot only slow down the object is at it's very right side. However, the IR sensors shows all reading without any problem. Here is my code:

#include <ros/ros.h>
#include <roomba_500_series/RoombaIR.h>
#include <geometry_msgs/Twist.h>
#include <ros/rate.h>
#include <iostream>

using namespace std;   

ros::Publisher pub_vel;
geometry_msgs::Twist cmdvel;

int reading, condition;
double speed;

//define the irsensorCallback function
void irsensorCallback(const roomba_500_series::RoombaIR::ConstPtr& msg)
{
  reading = msg->signal;
  condition = msg->state;
  cout<<"IR State = "<<reading<<endl;
  cout<<"IR Signal = "<<condition<<endl;

 if(condition!=0 || reading=>100)
   {
      cmdvel.linear.x=0.08;
      cmdvel.amgular.z=0.0;
   }
 else
   {
      cmdvel.linear.x=0.2;
      cmdvel.amgular.z=0.0;
   }
pub_vel.publish(cmdvel);
} 

//ROS node entry point 
int main(int argc, char **argv)
{
   ros::init(argc, argv, "turtlebot_test");
   ros::NodeHandle n;

   ros::Subscriber irsensorSubscriber = n.subscribe("/ir_bumper", 1000, irsensorCallback);
   ros::Publisher velocityPublisher = n.advertise<geometry_msgs::Twist>("cmd_vel", 1000);

  cmdvel.linear.x = 0.0;
  cmdvel.angular.z = 0.0;

   ros::spin();
   return 0;
}

Hopefully somebody could advise me on this. Thank you.

edit retag flag offensive close merge delete

Comments

Your code looks pretty reasonable. Are you sure you're interpreting the IR readings from the Roomba correctly?

ahendrix gravatar imageahendrix ( 2014-10-14 16:04:26 -0600 )edit

Yes I am sure. Because IR readings display all readings from all sensors. However, the turtlebot only slow down if the IR reading from very right side is less than 100. Any idea?

nadal11 gravatar imagenadal11 ( 2014-10-15 05:10:40 -0600 )edit

Is each sensor reading published as a separate message? Is it possible that you're publishing a command for each sensor reading, and only the most recent command is being used?

ahendrix gravatar imageahendrix ( 2014-10-15 10:59:40 -0600 )edit

yes, each sensor reading published as a separate message. And yes, the sensor reading from very right is the last sensor reading published and only this sensor reading is being used. that's why I wonder how I could make sure all other sensor reading are being used as well.

nadal11 gravatar imagenadal11 ( 2014-10-17 09:13:37 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-10-17 11:50:09 -0600

ahendrix gravatar image

If each sensor is published as a separate message on the same topic, your node should probably be collecting the readings across all sensors and making a decision based on all of the data, rather than just on the most recent reading.

I haven't worked with the roomba_500 node personally, but I suspect each IR sensor is published with a different frame_id in the header, which should allow you to tell them apart.

edit flag offensive delete link more
0

answered 2014-10-21 04:14:37 -0600

nadal11 gravatar image

That the problem as well. They have been published in the message on the same frame_id as well. Here is the code from roomba_560 for irsensor part.

rooomba_500_series::RoombaIR irbumper;
irbumper.header.stamp = current_time;

irbumper.header.frame_id = "base_irbumper_left";
irbumper.state = roomba->ir_bumper_[LEFT];
irbumper.signal = roomba->ir_bumper_signal_[LEFT];
irbumper_pub.publish(irbumper);

irbumper.header.frame_id = "base_irbumper_front_left";
irbumper.state = roomba->ir_bumper_[FRONT_LEFT];
irbumper.signal = roomba->ir_bumper_signal_[FRONT_LEFT];
irbumper_pub.publish(irbumper);

irbumper.header.frame_id = "base_irbumper_center_left";
irbumper.state = roomba->ir_bumper_[CENTER_LEFT];
irbumper.signal = roomba->ir_bumper_signal_[CENTER_LEFT];
irbumper_pub.publish(irbumper);

irbumper.header.frame_id = "base_irbumper_centre_right";
irbumper.state = roomba->ir_bumper_[CENTER_RIGHT];
irbumper.signal = roomba->ir_bumper_signal_[CENTER_RIGHT];
irbumper_pub.publish(irbumper);

irbumper.header.frame_id = "base_irbumper_front_right";
irbumper.state = roomba->ir_bumper_[FRONT_RIGHT];
irbumper.signal = roomba->ir_bumper_signal_[FRONT_RIGHT];
irbumper_pub.publish(irbumper);

irbumper.header.frame_id = "base_irbumper_right";
irbumper.state = roomba->ir_bumper_[RIGHT];
irbumper.signal = roomba->ir_bumper_signal_[RIGHT];
irbumper_pub.publish(irbumper);

and the turtlebot only slow down if there is any change of ir reading from ir_bumper_[RIGHT]

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-09-15 10:51:51 -0600

Seen: 339 times

Last updated: Oct 21 '14