Skip to content

Commit 1d86da8

Browse files
committed
WIP ProgramStateMessage
1 parent 6f87e4b commit 1d86da8

File tree

6 files changed

+80
-12
lines changed

6 files changed

+80
-12
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ add_library(urcl SHARED
2121
src/comm/server.cpp
2222
src/primary/primary_client.cpp
2323
src/primary/primary_package.cpp
24+
src/primary/program_state_message.cpp
2425
src/primary/robot_message.cpp
2526
src/primary/robot_state.cpp
27+
src/primary/program_state_message/global_variables_update_message.cpp
2628
src/primary/robot_message/error_code_message.cpp
2729
src/primary/robot_message/runtime_exception_message.cpp
2830
src/primary/robot_message/version_message.cpp

examples/primary_pipeline.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
#include <ur_client_library/comm/pipeline.h>
2929
#include <ur_client_library/comm/producer.h>
30-
#include <ur_client_library/comm/shell_consumer.h>
30+
#include <ur_client_library/primary/primary_shell_consumer.h>
3131
#include <ur_client_library/primary/primary_parser.h>
3232

3333
#ifdef ROS_BUILD
@@ -38,7 +38,7 @@ using namespace urcl;
3838

3939
// In a real-world example it would be better to get those values from command line parameters / a better configuration
4040
// system such as Boost.Program_options
41-
const std::string ROBOT_IP = "192.168.56.101";
41+
const std::string ROBOT_IP = "172.17.0.2";
4242

4343
int main(int argc, char* argv[])
4444
{
@@ -60,7 +60,7 @@ int main(int argc, char* argv[])
6060

6161
// The shell consumer will print the package contents to the shell
6262
std::unique_ptr<comm::IConsumer<primary_interface::PrimaryPackage>> consumer;
63-
consumer.reset(new comm::ShellConsumer<primary_interface::PrimaryPackage>());
63+
consumer.reset(new primary_interface::PrimaryShellConsumer());
6464

6565
// The notifer will be called at some points during connection setup / loss. This isn't fully
6666
// implemented atm.
@@ -70,6 +70,18 @@ int main(int argc, char* argv[])
7070
comm::Pipeline<primary_interface::PrimaryPackage> pipeline(prod, consumer.get(), "Pipeline", notifier);
7171
pipeline.run();
7272

73+
std::this_thread::sleep_for(std::chrono::seconds(2));
74+
75+
std::string script_code = "zero_ftsensor()";
76+
77+
auto program_with_newline = script_code + '\n';
78+
79+
size_t len = program_with_newline.size();
80+
const uint8_t* data = reinterpret_cast<const uint8_t*>(program_with_newline.c_str());
81+
size_t written;
82+
83+
primary_stream.write(data, len, written);
84+
7385
// Package contents will be printed while not being interrupted
7486
// Note: Packages for which the parsing isn't implemented, will only get their raw bytes printed.
7587
while (true)

include/ur_client_library/primary/abstract_primary_consumer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "ur_client_library/primary/robot_message/text_message.h"
3737
#include "ur_client_library/primary/robot_message/version_message.h"
3838
#include "ur_client_library/primary/robot_state/kinematics_info.h"
39+
#include "ur_client_library/primary/program_state_message/global_variables_update_message.h"
3940

4041
namespace urcl
4142
{
@@ -80,6 +81,8 @@ class AbstractPrimaryConsumer : public comm::IConsumer<PrimaryPackage>
8081
virtual bool consume(TextMessage& pkg) = 0;
8182
virtual bool consume(VersionMessage& pkg) = 0;
8283
virtual bool consume(KinematicsInfo& pkg) = 0;
84+
virtual bool consume(ProgramStateMessage& pkg) = 0;
85+
virtual bool consume(GlobalVariablesUpdateMessage& pkg) = 0;
8386

8487
private:
8588
/* data */

include/ur_client_library/primary/primary_parser.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "ur_client_library/primary/robot_message/runtime_exception_message.h"
3333
#include "ur_client_library/primary/robot_message/text_message.h"
3434
#include "ur_client_library/primary/robot_message/version_message.h"
35+
#include "ur_client_library/primary/program_state_message/global_variables_update_message.h"
36+
3537

3638
namespace urcl
3739
{
@@ -138,6 +140,28 @@ class PrimaryParser : public comm::Parser<PrimaryPackage>
138140
break;
139141
}
140142

143+
case RobotPackageType::PROGRAM_STATE_MESSAGE:
144+
{
145+
uint64_t timestamp;
146+
ProgramStateMessageType state_type;
147+
LOG_DEBUG("ProgramStateMessage received");
148+
149+
bp.parse(timestamp);
150+
bp.parse(state_type);
151+
152+
LOG_DEBUG("ProgramStateMessage of type %d received", static_cast<int>(state_type));
153+
154+
std::unique_ptr<PrimaryPackage> packet(programStateFromType(state_type, timestamp));
155+
if (!packet->parseWith(bp))
156+
{
157+
LOG_ERROR("Package parsing of type %d failed!", static_cast<int>(state_type));
158+
return false;
159+
}
160+
161+
results.push_back(std::move(packet));
162+
return true;
163+
}
164+
141165
default:
142166
{
143167
LOG_DEBUG("Invalid robot package type recieved: %u", static_cast<uint8_t>(type));
@@ -190,6 +214,21 @@ class PrimaryParser : public comm::Parser<PrimaryPackage>
190214
return new RobotMessage(timestamp, source, type);
191215
}
192216
}
217+
218+
ProgramStateMessage* programStateFromType(ProgramStateMessageType type, uint64_t timestamp)
219+
{
220+
switch(type)
221+
{
222+
//case ProgramStateMessageType::GLOBAL_VARIABLES_SETUP:
223+
//return new GlobalVariablesSetupMessage(timestamp);
224+
case ProgramStateMessageType::GLOBAL_VARIABLES_UPDATE:
225+
return new GlobalVariablesUpdateMessage(timestamp);
226+
//case ProgramStateMessageType::TYPE_VARIABLES_UPDATE:
227+
//return new TypeVariablesUpdateMessage(timestamp);
228+
default:
229+
return new ProgramStateMessage(timestamp, type);
230+
}
231+
}
193232
};
194233

195234
} // namespace primary_interface

include/ur_client_library/primary/primary_shell_consumer.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ class PrimaryShellConsumer : public AbstractPrimaryConsumer
8282
LOG_INFO("%s", msg.toString().c_str());
8383
return true;
8484
}
85+
virtual bool consume(ProgramStateMessage& msg) override
86+
{
87+
LOG_INFO("---ProgramStateMessage---%s", msg.toString().c_str());
88+
return true;
89+
}
90+
virtual bool consume(GlobalVariablesUpdateMessage& msg) override
91+
{
92+
LOG_INFO("---GlobalVariablesUpdateMessage---\n%s", msg.toString().c_str());
93+
return true;
94+
}
8595

8696
private:
8797
/* data */

src/primary/primary_client.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,21 @@ PrimaryClient::PrimaryClient(const std::string& robot_ip, const std::string& cal
4141
producer_.reset(new comm::URProducer<PrimaryPackage>(*stream_, parser_));
4242
producer_->setupProducer();
4343

44-
consumer_.reset(new PrimaryConsumer());
45-
std::shared_ptr<CalibrationChecker> calibration_checker(new CalibrationChecker(calibration_checksum));
46-
consumer_->setKinematicsInfoHandler(calibration_checker);
44+
//consumer_.reset(new PrimaryConsumer());
45+
//std::shared_ptr<CalibrationChecker> calibration_checker(new CalibrationChecker(calibration_checksum));
46+
//consumer_->setKinematicsInfoHandler(calibration_checker);
4747

48+
std::unique_ptr<comm::IConsumer<primary_interface::PrimaryPackage>> consumer;
49+
consumer.reset(new primary_interface::PrimaryShellConsumer());
4850
pipeline_.reset(new comm::Pipeline<PrimaryPackage>(*producer_, consumer_.get(), "primary pipeline", notifier_));
4951
pipeline_->run();
5052

51-
calibration_checker->isChecked();
52-
while (!calibration_checker->isChecked())
53-
{
54-
std::this_thread::sleep_for(std::chrono::seconds(1));
55-
}
56-
LOG_DEBUG("Got calibration information from robot.");
53+
//calibration_checker->isChecked();
54+
//while (!calibration_checker->isChecked())
55+
//{
56+
//std::this_thread::sleep_for(std::chrono::seconds(1));
57+
//}
58+
//LOG_DEBUG("Got calibration information from robot.");
5759
}
5860

5961
bool PrimaryClient::sendScript(const std::string& script_code)

0 commit comments

Comments
 (0)