Skip to content

Commit bcd4d28

Browse files
committed
Allow an empty input recipe to the RTDE client
1 parent a55257d commit bcd4d28

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

include/ur_client_library/rtde/data_package.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ class DataPackage : public RTDEPackage
7171
this->protocol_version_ = other.protocol_version_;
7272
}
7373

74+
DataPackage& operator=(DataPackage& other)
75+
{
76+
this->data_ = other.data_;
77+
this->recipe_ = other.recipe_;
78+
this->protocol_version_ = other.protocol_version_;
79+
return *this;
80+
}
81+
82+
DataPackage operator=(const DataPackage& other)
83+
{
84+
this->data_ = other.data_;
85+
this->recipe_ = other.recipe_;
86+
this->protocol_version_ = other.protocol_version_;
87+
return *this;
88+
}
89+
7490
/*!
7591
* \brief Creates a new DataPackage object, based on a given recipe.
7692
*
@@ -82,6 +98,7 @@ class DataPackage : public RTDEPackage
8298
: RTDEPackage(PackageType::RTDE_DATA_PACKAGE), recipe_(recipe), protocol_version_(protocol_version)
8399
{
84100
}
101+
85102
virtual ~DataPackage() = default;
86103

87104
/*!

include/ur_client_library/rtde/rtde_writer.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ class RTDEWriter
6767
writer_thread_.join();
6868
}
6969
}
70+
71+
/*!
72+
* \brief Sets a new input recipe. This can be used to change the input recipe on the fly, if
73+
* needed.
74+
*
75+
* \param recipe The new recipe to use
76+
*/
77+
void setInputRecipe(const std::vector<std::string>& recipe);
78+
7079
/*!
7180
* \brief Starts the writer thread, which periodically clears the queue to write packages to the
7281
* robot.
@@ -162,7 +171,7 @@ class RTDEWriter
162171
uint8_t pinToMask(uint8_t pin);
163172
comm::URStream<RTDEPackage>* stream_;
164173
std::vector<std::string> recipe_;
165-
uint8_t recipe_id_;
174+
uint8_t recipe_id_ = 0;
166175
moodycamel::BlockingReaderWriterQueue<std::unique_ptr<DataPackage>> queue_;
167176
std::thread writer_thread_;
168177
bool running_;

src/rtde/rtde_client.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ RTDEClient::RTDEClient(std::string robot_ip, comm::INotifier& notifier, const st
4141
: stream_(robot_ip, UR_RTDE_PORT)
4242
, output_recipe_(ensureTimestampIsPresent(readRecipe(output_recipe_file)))
4343
, ignore_unavailable_outputs_(ignore_unavailable_outputs)
44-
, input_recipe_(readRecipe(input_recipe_file))
4544
, parser_(output_recipe_)
4645
, prod_(std::make_unique<comm::URProducer<RTDEPackage>>(stream_, parser_))
4746
, notifier_(notifier)
@@ -51,6 +50,11 @@ RTDEClient::RTDEClient(std::string robot_ip, comm::INotifier& notifier, const st
5150
, target_frequency_(target_frequency)
5251
, client_state_(ClientState::UNINITIALIZED)
5352
{
53+
if (!input_recipe_file.empty())
54+
{
55+
input_recipe_ = readRecipe(input_recipe_file);
56+
writer_.setInputRecipe(input_recipe_);
57+
}
5458
}
5559

5660
RTDEClient::RTDEClient(std::string robot_ip, comm::INotifier& notifier, const std::vector<std::string>& output_recipe,
@@ -169,9 +173,12 @@ void RTDEClient::setupCommunication(const size_t max_num_tries, const std::chron
169173
return;
170174
}
171175

172-
setupInputs();
173-
if (client_state_ == ClientState::UNINITIALIZED)
174-
return;
176+
if (input_recipe_.size() > 0)
177+
{
178+
setupInputs();
179+
if (client_state_ == ClientState::UNINITIALIZED)
180+
return;
181+
}
175182

176183
// We finished communication for now
177184
pipeline_->stop();

src/rtde/rtde_writer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ RTDEWriter::RTDEWriter(comm::URStream<RTDEPackage>* stream, const std::vector<st
3737
{
3838
}
3939

40+
void RTDEWriter::setInputRecipe(const std::vector<std::string>& recipe)
41+
{
42+
std::lock_guard<std::mutex> guard(package_mutex_);
43+
recipe_ = recipe;
44+
package_ = DataPackage(recipe_);
45+
package_.initEmpty();
46+
}
47+
4048
void RTDEWriter::init(uint8_t recipe_id)
4149
{
4250
recipe_id_ = recipe_id;

0 commit comments

Comments
 (0)