EmergencyStop.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarXCore::ArmarXObjects::EmergencyStop
17 * @author Stefan Reither ( stef dot reither at web dot de )
18 * @date 2016
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#include "EmergencyStop.h"
24
25#include <mutex>
26
27namespace armarx
28{
29
30 void
31 EmergencyStopMaster::setEmergencyStopState(EmergencyStopState state, const ::Ice::Current&)
32 {
33 const std::unique_lock lock{ss2StateMutex};
34
35 currentSS2State = state;
36
37 if (currentSS2State == EmergencyStopState::eEmergencyStopActive)
38 {
39 lastSS2Activation = armarx::core::time::DateTime::Now();
40 }
41
42 this->emergencyStopTopic->reportEmergencyStopState(currentSS2State);
43 }
44
45 EmergencyStopState
46 EmergencyStopMaster::trySetEmergencyStopState(EmergencyStopState targetState,
47 const ::Ice::Current&)
48 {
50
51 // If the SS2 should be released (target state = inactive) we check whether the last
52 // activation happened at least before safeDuration.
53 if (targetState == EmergencyStopState::eEmergencyStopInactive and
54 armarx::core::time::DateTime::Now() > lastSS2Activation + safeDuration)
55 {
56 setEmergencyStopState(targetState);
57 }
58
59 return getEmergencyStopState();
60 }
61
62 EmergencyStopState
63 EmergencyStopMaster::getEmergencyStopState(const ::Ice::Current& /*unused*/) const
64 {
65 const std::shared_lock lock{ss2StateMutex};
66
67 return currentSS2State;
68 }
69
70 void
76
77 void
79 {
81 getProperty<std::string>("EmergencyStopTopic").getValue());
82
83 // Default state is inactive
84 this->setEmergencyStopState(EmergencyStopState::eEmergencyStopInactive);
85 }
86
93
94} // namespace armarx
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
EmergencyStopState getEmergencyStopState(const ::Ice::Current &=Ice::emptyCurrent) const override
void setEmergencyStopState(EmergencyStopState state, const ::Ice::Current &=Ice::emptyCurrent) override
Sets the state of the EmergencyStop and sends the new state immediatly over the specified topic.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onConnectComponent() override
EmergencyStopState trySetEmergencyStopState(EmergencyStopState targetState, const ::Ice::Current &=Ice::emptyCurrent) override
Try set the SS2 emergency stop state if it is safe.
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
static DateTime Now()
Definition DateTime.cpp:51
Represents a duration.
Definition Duration.h:17
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition Duration.cpp:48
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.