The following code was added in the
/home/husarion/ros_workspace/src/rosbot_webui/src/
folder where pose_to_tf.cpp and tf_to_pose.cpp files are which similarlly publish nodes/topics.
#include <ros/ros.h>
#include <std_msgs/Bool.h>
#include <hFramework.h> //this is the line added in to resolve the hSens1.pin2 reference
std_msgs::Bool button;
ros::Publisher button_pub;
bool last_reading;
ros::Time last_debounce_time;
ros::Duration debounce_delay(0.05);
bool published = true;
void buttonProcess(void)
{
bool reading = ! hSens1.pin2.read();
if (last_reading!= reading){
last_debounce_time = ros::Time::now();
published = false;
}
//if the button value has not changed for the debounce delay, we know its stable
if ( !published && ((ros::Time::now() - last_debounce_time) > debounce_delay)) {
button.data = reading;
button_pub.publish(button);
published = true;
}
last_reading = reading;
}
int main(int argc, char **argv)
{
ros::init(argc, argv, “button_push”);
ros::NodeHandle node;
ros::Rate loop_rate(10);
button_pub = node.advertise<std_msgs::Bool>("/next_op",1);
hSens1.pin2.setIn_pu();
last_reading = ! hSens1.pin2.read();
while(ros::ok()) {
buttonProcess();
ros::spinOnce();
loop_rate.sleep();
}
return 0;
};
Thanks,
bobg