Skip to content

Commit 4dccf48

Browse files
committed
Skip checking whether there already is a program running
1 parent d36121a commit 4dccf48

File tree

4 files changed

+14
-45
lines changed

4 files changed

+14
-45
lines changed

include/ur_client_library/exceptions.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <chrono>
3333
#include <stdexcept>
3434
#include <sstream>
35-
#include <string>
3635
#include "ur/version_information.h"
3736

3837
#ifdef _WIN32
@@ -204,22 +203,5 @@ class MissingArgument : public UrException
204203
return text_.c_str();
205204
}
206205
};
207-
208-
class InvalidStateForCommand : public UrException
209-
{
210-
private:
211-
std::string text_;
212-
213-
public:
214-
explicit InvalidStateForCommand() = delete;
215-
explicit InvalidStateForCommand(std::string text) : std::runtime_error(text)
216-
{
217-
text_ = text;
218-
}
219-
virtual const char* what() const noexcept override
220-
{
221-
return text_.c_str();
222-
}
223-
};
224206
} // namespace urcl
225207
#endif // ifndef UR_CLIENT_LIBRARY_EXCEPTIONS_H_INCLUDED

include/ur_client_library/primary/primary_client.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,14 @@ class PrimaryClient
146146
/*!
147147
* /brief Stop execution of a running or paused program
148148
*
149-
* Blocks until the robot has come to a standstill (while following
150-
* the program path) and stopped program execution.
151-
*
152-
* \param already_stopped_ok If true, the function will return true if the robot is already
153-
* stopped.
154149
* \param validate If true, the function will block until the robot has stopped or the timeout
155150
* passed by.
156151
* \param timeout The maximum time to wait for the robot to stop the program.
157152
*
158153
* \throws urcl::UrException if the command cannot be sent to the robot.
159154
* \throws urcl::TimeoutException if the robot doesn't stop the program within the given timeout.
160155
*/
161-
void commandStop(const bool already_stopped_ok = false, const bool validate = true,
162-
const std::chrono::milliseconds timeout = std::chrono::seconds(2));
156+
void commandStop(const bool validate = true, const std::chrono::milliseconds timeout = std::chrono::seconds(2));
163157

164158
/*!
165159
* \brief Get the latest robot mode.

src/primary/primary_client.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -238,28 +238,14 @@ void PrimaryClient::commandUnlockProtectiveStop(const bool validate, const std::
238238
}
239239
}
240240

241-
void PrimaryClient::commandStop(const bool already_stopped_ok, const bool validate,
242-
const std::chrono::milliseconds timeout)
241+
void PrimaryClient::commandStop(const bool validate, const std::chrono::milliseconds timeout)
243242
{
244243
std::shared_ptr<RobotModeData> robot_mode_data = consumer_->getRobotModeData();
245244
if (robot_mode_data == nullptr)
246245
{
247246
throw UrException("Stopping a program while robot state is unknown. This should not happen");
248247
}
249248

250-
if (!(robot_mode_data->is_program_running_ || robot_mode_data->is_program_paused_))
251-
{
252-
if (already_stopped_ok)
253-
{
254-
URCL_LOG_DEBUG("Program halt requested, but program is already stopped, skipping.");
255-
return;
256-
}
257-
else
258-
{
259-
throw InvalidStateForCommand("Cannot halt program execution, as no program is running or paused on the robot.");
260-
}
261-
}
262-
263249
if (!sendScript("stop program"))
264250
{
265251
throw UrException("Failed to send the command `stop program` to robot");

tests/test_primary_client.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,22 @@ TEST_F(PrimaryClientTest, test_stop_command)
153153
EXPECT_NO_THROW(client_->commandStop());
154154
EXPECT_FALSE(client_->getRobotModeData()->is_program_running_);
155155

156-
// Without a program running it should throw an exception
157-
EXPECT_THROW(client_->commandStop(), InvalidStateForCommand);
156+
// Without a program running it should not throw an exception
157+
EXPECT_NO_THROW(client_->commandStop());
158158

159-
// We can specifically allow to be stopped already
160-
EXPECT_NO_THROW(client_->commandStop(true));
159+
EXPECT_TRUE(client_->sendScript(script_code));
160+
waitFor([this]() { return client_->getRobotModeData()->is_program_running_; }, std::chrono::seconds(5));
161+
EXPECT_THROW(client_->commandStop(true, std::chrono::milliseconds(1)), TimeoutException);
162+
EXPECT_NO_THROW(waitFor(
163+
[this]() {
164+
return !client_->getRobotModeData()->is_program_running_ && !client_->getRobotModeData()->is_program_paused_;
165+
},
166+
std::chrono::seconds(5)));
161167

168+
// without validation
162169
EXPECT_TRUE(client_->sendScript(script_code));
163170
waitFor([this]() { return client_->getRobotModeData()->is_program_running_; }, std::chrono::seconds(5));
164-
EXPECT_THROW(client_->commandStop(true, true, std::chrono::milliseconds(1)), TimeoutException);
171+
EXPECT_NO_THROW(client_->commandStop(false));
165172
EXPECT_NO_THROW(waitFor(
166173
[this]() {
167174
return !client_->getRobotModeData()->is_program_running_ && !client_->getRobotModeData()->is_program_paused_;

0 commit comments

Comments
 (0)