forked from strands-project/scitos_drivers
-
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.
Created separate launch file for MIRA framework and took out function…
…ality in scitos_node. Added MIRA units for implementing the proposed watchdog behaviour in issue strands-project#98.
- Loading branch information
Showing
6 changed files
with
146 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" ?> | ||
<launch> | ||
<!-- scitos_modules argument; must be a space seperated list of hardware modules to load --> | ||
<arg name="SCITOS_CONFIG" default="$(find scitos_mira)/resources/SCITOSDriver.xml"/> | ||
|
||
<node pkg="scitos_mira" type="startMiraFramework.sh" args="$(arg SCITOS_CONFIG)" name="startMiraFramework" output="screen"> | ||
</node> | ||
</launch> |
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,11 @@ | ||
#!/bin/bash | ||
|
||
source ~/.bashrc | ||
|
||
############################################################################## | ||
|
||
while [ true ] ; do | ||
echo "Starting MIRA framework at `date`" | ||
mira $1 -p1234 | ||
sleep 5 | ||
done |
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,50 @@ | ||
/** | ||
* @file BridgeWatchdogClient.C | ||
* Will continuously send pings to a channel to notify a BridgeWatchdogServer that everything is okay. | ||
* | ||
* @author Christian Reuther | ||
* @date 2015/02/12 | ||
*/ | ||
|
||
#include <fw/Unit.h> | ||
#include <serialization/Serialization.h> | ||
|
||
namespace mira { | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
class BridgeWatchdogClient : public Unit | ||
{ | ||
MIRA_OBJECT(BridgeWatchdogClient) | ||
|
||
public: | ||
// Spin with 100 milliseconds precision. This can be altered using the serialization interface | ||
BridgeWatchdogClient() : Unit(Duration::milliseconds(100)) { | ||
mMaxPingAge = Duration::seconds(2); | ||
} | ||
|
||
template<typename Reflector> void reflect(Reflector& r) | ||
{ | ||
// Reflect the basic service methods of the base class mira::Unit. | ||
Unit::reflect(r); | ||
} | ||
|
||
protected: | ||
virtual void initialize() { | ||
mWatchdogChannel = publish<std::string>("/BridgeWatchdog"); | ||
} | ||
|
||
virtual void process(const Timer& timer) { | ||
// Will get the current timestamp | ||
mWatchdogChannel.post("OK"); | ||
} | ||
|
||
protected: | ||
Channel<std::string> mWatchdogChannel; | ||
}; | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
} | ||
|
||
MIRA_CLASS_SERIALIZATION(mira::BridgeWatchdogClient, mira::Unit); |
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,75 @@ | ||
/** | ||
* @file BridgeWatchdogServer.C | ||
* Will call emergency stop if there is no update to the "/BridgeWatchdog" channel for a certain time. | ||
* | ||
* @author Christian Reuther | ||
* @date 2015/02/12 | ||
*/ | ||
|
||
#include <fw/Unit.h> | ||
#include <serialization/Serialization.h> | ||
|
||
namespace mira { | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
class BridgeWatchdogServer : public Unit | ||
{ | ||
MIRA_OBJECT(BridgeWatchdogServer) | ||
|
||
public: | ||
// Spin with 100 milliseconds precision | ||
BridgeWatchdogServer() : Unit(Duration::milliseconds(100)) { | ||
mMaxPingAge = Duration::seconds(2); | ||
} | ||
|
||
template<typename Reflector> void reflect(Reflector& r) | ||
{ | ||
// Reflect the basic service methods of the base class mira::Unit. | ||
Unit::reflect(r); | ||
|
||
// Set it as a property so it can be changed at runtime | ||
r.property("MaxPingAge", mMaxPingAge, "Maximum duration between pings before emergencyStop is triggered", Duration::seconds(2)); | ||
} | ||
|
||
protected: | ||
virtual void initialize() { | ||
mWatchdogChannel = subscribe<std::string>("/BridgeWatchdog"); | ||
|
||
// Definitely wait until robot service is available. | ||
waitForService("/robot/Robot", Duration::seconds(10)); | ||
} | ||
|
||
virtual void process(const Timer& timer) { | ||
const Time now = Time::now(); | ||
|
||
// Get data from watchdog channel and check the timestamp | ||
try { | ||
auto read = mWatchdogChannel.read(); | ||
if(Duration(now - read->timestamp).totalMilliseconds() > mMaxPingAge) | ||
triggerEmergencyStop(); | ||
} catch(...) { | ||
// Something went wrong, we should definitely stop just in case | ||
triggerEmergencyStop(); | ||
} | ||
} | ||
|
||
protected: | ||
void triggerEmergencyStop() { | ||
MIRA_LOG(ERROR) << "BridgeWatchdogServer: Triggered emergency stop!"; | ||
|
||
auto rpcFuture = callService<void>("/robot/Robot", "emergencyStop"); | ||
rpcFuture.wait(); | ||
rpcFuture.get(); // get an exception if it occurred - nothing we can do though | ||
} | ||
|
||
protected: | ||
Channel<std::string> mWatchdogChannel; | ||
Duration mMaxPingAge; | ||
}; | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
} | ||
|
||
MIRA_CLASS_SERIALIZATION(mira::BridgeWatchdogServer, mira::Unit); |
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