Skip to content

Commit

Permalink
adds stop command if no velocity received for 0.5 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Medvedev committed Nov 17, 2012
1 parent 3d9eaab commit e3850e9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
10 changes: 10 additions & 0 deletions atrvjr_drivers/rflex/include/rflex/atrvjr_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <rflex/rflex_driver.h>
#include <sensor_msgs/PointCloud.h>
#include <boost/thread.hpp>

/**
* \brief ATRVJR Driver class
Expand Down Expand Up @@ -52,6 +53,12 @@ class ATRVJR : public RFLEX {
* \return number of active bump sensors */
// int getBaseBumps(sensor_msgs::PointCloud* cloud) const;

/**
* Overriding rflex setVelocity to be able to watch when no
* velocity command arrives within interval.
*/
void setVelocity( const double tvel, const double rvel);

/** Processes the DIO packets - called from RFflex Driver
* \param address origin
* \param data values */
Expand Down Expand Up @@ -83,6 +90,9 @@ class ATRVJR : public RFLEX {

// int** bumps;

ros::Time last_velocity_time;
void watchdogThread();///< Thread that stops robot if no vel command received

// Not allowed to use these
ATRVJR(const ATRVJR &atrvjr); ///< Private constructor - Don't use
ATRVJR &operator=(const ATRVJR &atrvjr); ///< Private constructor - Don't use
Expand Down
20 changes: 19 additions & 1 deletion atrvjr_drivers/rflex/src/atrvjr_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@
#include <rflex/atrvjr_config.h>
#include <math.h>
#include <cstdio>
#include <boost/thread.hpp>

ATRVJR::ATRVJR()
ATRVJR::ATRVJR():
last_velocity_time(ros::Time::now())
{
// Start watchdog thread
boost::thread(boost::bind(&ATRVJR::watchdogThread, this));
// bumps = new int*[2];
//
// for (int index=0;index<2;index++) {
Expand Down Expand Up @@ -167,3 +171,17 @@ void ATRVJR::processDioEvent(unsigned char address, unsigned short data) {
printf("ATRVJR DIO: address 0x%02x (%d) value 0x%02x (%d)\n", address, address, data, data);
}
}

void ATRVJR::setVelocity(const double tvel, const double rvel) {
last_velocity_time = ros::Time::now();
RFLEX::setVelocity(tvel, rvel);
}

void ATRVJR::watchdogThread() {
while (true) {
if (ros::Time::now() - last_velocity_time > ros::Duration(0.5)) {
RFLEX::setVelocity(0, 0);
}
usleep(100000);
}
}
3 changes: 2 additions & 1 deletion atrvjr_drivers/rflex/src/atrvjr_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
*
*/
class ATRVJRNode {
public:
ros::NodeHandle n;
private:
ATRVJR driver;

Expand Down Expand Up @@ -72,7 +74,6 @@ class ATRVJRNode {
void reconfigureCb(rflex::AtrvjrParamsConfig& config, uint32_t level);

public:
ros::NodeHandle n;
ATRVJRNode();
~ATRVJRNode();
int initialize(const char* port);
Expand Down

0 comments on commit e3850e9

Please sign in to comment.