|
31 | 31 | #include <ur_client_library/primary/primary_client.h> |
32 | 32 | #include <ur_client_library/primary/robot_message.h> |
33 | 33 | #include <ur_client_library/primary/robot_state.h> |
| 34 | +#include "ur_client_library/exceptions.h" |
34 | 35 |
|
35 | 36 | namespace urcl |
36 | 37 | { |
@@ -160,44 +161,62 @@ bool PrimaryClient::checkCalibration(const std::string& checksum) |
160 | 161 | return kin_info->toHash() == checksum; |
161 | 162 | } |
162 | 163 |
|
163 | | -bool PrimaryClient::commandPowerOn(const bool validate, const std::chrono::milliseconds timeout) |
| 164 | +void PrimaryClient::commandPowerOn(const bool validate, const std::chrono::milliseconds timeout) |
164 | 165 | { |
165 | 166 | if (!sendScript("power on")) |
166 | 167 | { |
167 | | - return false; |
| 168 | + throw UrException("Failed to send power on command to robot"); |
168 | 169 | } |
169 | 170 |
|
170 | 171 | if (validate) |
171 | 172 | { |
172 | | - return waitFor([this]() { return getRobotMode() == RobotMode::IDLE; }, timeout); |
| 173 | + try |
| 174 | + { |
| 175 | + waitFor([this]() { return getRobotMode() == RobotMode::IDLE; }, timeout); |
| 176 | + } |
| 177 | + catch (const TimeoutException& ex) |
| 178 | + { |
| 179 | + throw TimeoutException("Robot did not power on within the given timeout", timeout); |
| 180 | + } |
173 | 181 | } |
174 | | - return true; |
175 | 182 | } |
176 | 183 |
|
177 | | -bool PrimaryClient::commandPowerOff(const bool validate, const std::chrono::milliseconds timeout) |
| 184 | +void PrimaryClient::commandPowerOff(const bool validate, const std::chrono::milliseconds timeout) |
178 | 185 | { |
179 | 186 | if (!sendScript("power off")) |
180 | 187 | { |
181 | | - return false; |
| 188 | + throw UrException("Failed to send power off command to robot"); |
182 | 189 | } |
183 | 190 | if (validate) |
184 | 191 | { |
185 | | - return waitFor([this]() { return getRobotMode() == RobotMode::POWER_OFF; }, timeout); |
| 192 | + try |
| 193 | + { |
| 194 | + waitFor([this]() { return getRobotMode() == RobotMode::POWER_OFF; }, timeout); |
| 195 | + } |
| 196 | + catch (const std::exception&) |
| 197 | + { |
| 198 | + throw TimeoutException("Robot did not power off within the given timeout", timeout); |
| 199 | + } |
186 | 200 | } |
187 | | - return true; |
188 | 201 | } |
189 | 202 |
|
190 | | -bool PrimaryClient::commandBrakeRelease(const bool validate, const std::chrono::milliseconds timeout) |
| 203 | +void PrimaryClient::commandBrakeRelease(const bool validate, const std::chrono::milliseconds timeout) |
191 | 204 | { |
192 | 205 | if (!sendScript("set robotmode run")) |
193 | 206 | { |
194 | | - return false; |
| 207 | + throw UrException("Failed to send brake release command to robot"); |
195 | 208 | } |
196 | 209 | if (validate) |
197 | 210 | { |
198 | | - return waitFor([this]() { return getRobotMode() == RobotMode::RUNNING; }, timeout); |
| 211 | + try |
| 212 | + { |
| 213 | + waitFor([this]() { return getRobotMode() == RobotMode::RUNNING; }, timeout); |
| 214 | + } |
| 215 | + catch (const std::exception&) |
| 216 | + { |
| 217 | + throw TimeoutException("Robot did not release the brakes within the given timeout", timeout); |
| 218 | + } |
199 | 219 | } |
200 | | - return true; |
201 | 220 | } |
202 | 221 |
|
203 | 222 | } // namespace primary_interface |
|
0 commit comments