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 
27 namespace 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
72  {
74  getProperty<std::string>("EmergencyStopTopic").getValue());
75  }
76 
77  void
79  {
80  emergencyStopTopic = armarx::ManagedIceObject::getTopic<EmergencyStopListenerPrx>(
81  getProperty<std::string>("EmergencyStopTopic").getValue());
82 
83  // Default state is inactive
84  this->setEmergencyStopState(EmergencyStopState::eEmergencyStopInactive);
85  }
86 
89  {
92  }
93 
94 } // namespace armarx
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
armarx::EmergencyStopMaster::trySetEmergencyStopState
EmergencyStopState trySetEmergencyStopState(EmergencyStopState targetState, const ::Ice::Current &=Ice::emptyCurrent) override
Try set the SS2 emergency stop state if it is safe.
Definition: EmergencyStop.cpp:46
EmergencyStop.h
armarx::EmergencyStopMaster::getEmergencyStopState
EmergencyStopState getEmergencyStopState(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: EmergencyStop.cpp:63
armarx::EmergencyStopPropertyMasterDefinitions
Definition: EmergencyStop.h:54
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:290
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::core::time::Duration
Represents a duration.
Definition: Duration.h:17
armarx::EmergencyStopMaster::onConnectComponent
void onConnectComponent() override
Definition: EmergencyStop.cpp:78
armarx::EmergencyStopMaster::onInitComponent
void onInitComponent() override
Definition: EmergencyStop.cpp:71
armarx::EmergencyStopMaster::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: EmergencyStop.cpp:88
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::EmergencyStopMaster::setEmergencyStopState
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.
Definition: EmergencyStop.cpp:31
armarx::core::time::Duration::MilliSeconds
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition: Duration.cpp:55