-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Siyuan Huang
committed
Apr 25, 2019
1 parent
6ec9fa4
commit 74e7f1e
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
#include "ros/ros.h" | ||
#include "std_msgs/String.h" | ||
#include "sensor_msgs/LaserScan.h" | ||
#include <vector> | ||
#include <math.h> | ||
|
||
using namespace std; | ||
int Samples = 720; | ||
#define PI 3.1415926 | ||
// The Sensor angle range is from -2/3 PI to 2/3PI, and the angle increment is 0.00672220578417 Deg | ||
std::vector<float> old_range = std::vector<float>(Samples, 0); | ||
std::vector<float> range = std::vector<float>(Samples, 0); | ||
std::vector<float> diff = std::vector<float>(Samples,0); | ||
|
||
void scanValues(const sensor_msgs::LaserScan::ConstPtr& scan) | ||
{ | ||
/*The Laser has 720 Samples */ | ||
|
||
range = scan->ranges; | ||
double angle,x,y; | ||
float safe_d = 2; | ||
float warn_d = 1.5; | ||
float distance_now; | ||
//cout<<range[100]<<endl; | ||
for(int i = 1; i<=Samples;i++) | ||
{ | ||
diff[i] = range[i] - old_range[i]; | ||
|
||
if ( abs(diff[i]) > 0.1 && abs(diff[i]) < 100 ) { | ||
|
||
distance_now = diff[i]; | ||
//distance_now = sqrt(x*x+y*y); | ||
|
||
if(distance_now>safe_d) { | ||
ROS_INFO("Safety!"); | ||
|
||
} | ||
else if(distance_now>warn_d&&distance_now<safe_d) { | ||
|
||
ROS_INFO("Critical!"); | ||
} | ||
else if (distance_now<(warn_d)) { | ||
ROS_INFO("Dangerous!"); | ||
} | ||
|
||
} | ||
|
||
} | ||
old_range = range; | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
ros::init(argc, argv, "static"); | ||
ros::NodeHandle n; | ||
ros::Subscriber sub; | ||
//sub = n.subscribe("/mybot/laser/scan", 50, scanValues); | ||
sub = n.subscribe("/sick_safetyscanners/scan", 50, scanValues); | ||
|
||
|
||
ros::spin(); | ||
return 0; | ||
} | ||
|