Skip to content

Commit 1cecc87

Browse files
authored
Apply suggestions from code review
1 parent b264b21 commit 1cecc87

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

include/ur_client_library/primary/primary_client.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,27 @@ class PrimaryClient
2020
{
2121
public:
2222
PrimaryClient() = delete;
23-
PrimaryClient(comm::URStream<PrimaryPackage>& stream);
23+
PrimaryClient(const std::string& robot_ip, comm::INotifier& notifier);
2424
~PrimaryClient();
2525

2626
/*!
2727
* \brief Adds a primary consumer to the list of consumers
2828
*
2929
* \param primary_consumer Primary consumer that should be added to the list
3030
*/
31-
void addPrimaryConsumer (std::shared_ptr<AbstractPrimaryConsumer> primary_consumer);
31+
void addPrimaryConsumer (std::shared_ptr<comm::IConsumer<PrimaryPackage>> primary_consumer);
3232

3333
/*!
3434
* \brief Remove a primary consumer from the list of consumers
3535
*
3636
* \param primary_consumer Primary consumer that should be removed from the list
3737
*/
38-
void removePrimaryConsumer(std::shared_ptr<AbstractPrimaryConsumer> primary_consumer);
38+
void removePrimaryConsumer(std::shared_ptr<comm::IConsumer<PrimaryPackage>> primary_consumer);
3939
void start();
4040

41+
/*!
42+
* \brief Retrieves previously raised error codes from PrimaryClient. After calling this, recorded errors will be deleted.
43+
*/
4144
std::deque<ErrorCode> getErrorCodes();
4245

4346
private:
@@ -51,7 +54,7 @@ class PrimaryClient
5154

5255
comm::INotifier notifier_;
5356

54-
comm::URStream<PrimaryPackage>& stream_;
57+
comm::URStream<PrimaryPackage> stream_;
5558
std::unique_ptr<comm::URProducer<PrimaryPackage>> prod_;
5659
std::unique_ptr<comm::Pipeline<PrimaryPackage>> pipeline_;
5760

include/ur_client_library/ur/ur_driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ class UrDriver
536536
bool checkCalibration(const std::string& checksum);
537537

538538
/*!
539-
* \brief Retrieves error codes from PrimaryClient.
539+
* \brief Retrieves previously raised error codes from PrimaryClient. After calling this, recorded errors will be deleted.
540540
*
541541
* \returns list of error codes
542542
*

src/primary/primary_client.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ namespace urcl
66
{
77
namespace primary_interface
88
{
9-
PrimaryClient::PrimaryClient(comm::URStream<PrimaryPackage>& stream)
10-
: stream_(stream)
9+
PrimaryClient::PrimaryClient(const std::string& robot_ip, comm::INotifier& notifier)
10+
: stream_(robot_ip, UR_PRIMARY_PORT)
1111
{
1212
prod_.reset(new comm::URProducer<PrimaryPackage>(stream_, parser_));
1313

@@ -32,15 +32,16 @@ PrimaryClient::~PrimaryClient()
3232
void PrimaryClient::start()
3333
{
3434
URCL_LOG_INFO("Starting primary client pipeline");
35+
pipeline_->init();
3536
pipeline_->run();
3637
}
3738

38-
void PrimaryClient::addPrimaryConsumer(std::shared_ptr<AbstractPrimaryConsumer> primary_consumer)
39+
void PrimaryClient::addPrimaryConsumer(std::shared_ptr<comm::IConsumer<PrimaryPackage>> primary_consumer)
3940
{
4041
multi_consumer_->addConsumer(primary_consumer);
4142
}
4243

43-
void PrimaryClient::removePrimaryConsumer(std::shared_ptr<AbstractPrimaryConsumer> primary_consumer)
44+
void PrimaryClient::removePrimaryConsumer(std::shared_ptr<comm::IConsumer<PrimaryPackage>> primary_consumer)
4445
{
4546
multi_consumer_->removeConsumer(primary_consumer);
4647
}

src/ur/ur_driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ urcl::UrDriver::UrDriver(const std::string& robot_ip, const std::string& script_
7474
new comm::URStream<primary_interface::PrimaryPackage>(robot_ip_, urcl::primary_interface::UR_SECONDARY_PORT));
7575
secondary_stream_->connect();
7676

77-
primary_client_.reset(new urcl::primary_interface::PrimaryClient(*primary_stream_));
77+
primary_client_.reset(new urcl::primary_interface::PrimaryClient(robot_ip_, notifier_));
7878

7979
non_blocking_read_ = non_blocking_read;
8080
get_packet_timeout_ = non_blocking_read_ ? 0 : 100;

tests/test_ur_driver.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,10 @@ TEST_F(UrDriverTest, reset_rtde_client)
381381

382382
TEST_F(UrDriverTest, read_error_code)
383383
{
384+
g_consume_rtde_packages = true;
384385
g_ur_driver->startPrimaryClientCommunication();
386+
// Wait until we actually received a package
387+
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
385388
std::stringstream cmd;
386389
cmd << "sec setup():" << std::endl << " protective_stop()" << std::endl << "end";
387390
EXPECT_TRUE(g_ur_driver->sendScript(cmd.str()));
@@ -398,8 +401,8 @@ TEST_F(UrDriverTest, read_error_code)
398401
ASSERT_EQ(error_codes.at(0).message_code, 209);
399402
ASSERT_EQ(error_codes.at(0).message_argument, 0);
400403

401-
// Wait for 5s after PSTOP before clearing it
402-
std::this_thread::sleep_for(std::chrono::seconds(5));
404+
// Wait for after PSTOP before clearing it
405+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
403406

404407
EXPECT_TRUE(g_dashboard_client->commandCloseSafetyPopup());
405408
EXPECT_TRUE(g_dashboard_client->commandUnlockProtectiveStop());

0 commit comments

Comments
 (0)