-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetect_pickup.ino
106 lines (89 loc) · 1.79 KB
/
detect_pickup.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//#define sensorPin A0
//#include <ros.h>
//#include <std_msgs/String.h>
//
//ros::NodeHandle nh;
//
//std_msgs::String str_msg;
//ros::Publisher pickup_avail("pickup_avail", &str_msg);
//
//char msg[13] = "new object!";
//
//void setup()
//{
// nh.initNode();
// nh.advertise(pickup_avail);
// Serial.begin(115200);
//}
//
//bool object = 0;
//int count = 0;
//void loop()
//{
// int x = analogRead(sensorPin);
// Serial.println(x);
//
// if (x > 400){
// count++;
// }
// else{
// count = 0;
// object = 0;
// }
// if ((count > 10) && (object==0)){
// str_msg.data = msg;
// pickup_avail.publish( &str_msg );
// Serial.println(x);
// object = 1;
// }
//
//
// nh.spinOnce();
// delay(50);
//}
#include "Filter.h"
#include "MegunoLink.h" // for plotting
#include "ArduinoTimer.h" // for periodic measurement
#define sensorPin A0
#include <ros.h>
#include <std_msgs/String.h>
ros::NodeHandle nh;
std_msgs::String str_msg;
ros::Publisher pickup_avail("pickup_avail", &str_msg);
char msg[13] = "new object!";
// the <float> makes a filter for float numbers
// 20 is the weight (20 => 20%)
// 0 is the initial value of the filter
ExponentialFilter<float> Filtered(10, 0);
bool object = 0;
int count = 0;
void setup()
{
nh.initNode();
nh.advertise(pickup_avail);
// Serial.begin(115200);
}
void loop()
{
float Raw = analogRead(sensorPin);
Filtered.Filter(Raw);
float Smooth = Filtered.Current();
// Serial.print(Raw);
// Serial.print(",");
// Serial.println(Smooth);
if (Smooth > 600){
count++;
}
else{
count = 0;
object = 0;
}
if ((count > 10) && (object==0)){
str_msg.data = msg;
pickup_avail.publish( &str_msg );
// Serial.println("adshjk");
object = 1;
}
nh.spinOnce();
delay(25);
}