Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")
add_library(urcl SHARED
src/comm/tcp_socket.cpp
src/comm/server.cpp
src/primary/primary_client.cpp
src/primary/primary_package.cpp
src/primary/program_state_message.cpp
src/primary/robot_message.cpp
src/primary/robot_state.cpp
src/primary/program_state_message/global_variables_update_message.cpp
src/primary/robot_message/error_code_message.cpp
src/primary/robot_message/runtime_exception_message.cpp
src/primary/robot_message/version_message.cpp
src/primary/robot_message/text_message.cpp
src/primary/robot_message/key_message.cpp
src/primary/robot_state/kinematics_info.cpp
src/rtde/control_package_pause.cpp
src/rtde/control_package_setup_inputs.cpp
Expand Down
18 changes: 15 additions & 3 deletions examples/primary_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include <ur_client_library/comm/pipeline.h>
#include <ur_client_library/comm/producer.h>
#include <ur_client_library/comm/shell_consumer.h>
#include <ur_client_library/primary/primary_shell_consumer.h>
#include <ur_client_library/primary/primary_parser.h>

#ifdef ROS_BUILD
Expand All @@ -38,7 +38,7 @@ using namespace urcl;

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

int main(int argc, char* argv[])
{
Expand All @@ -60,7 +60,7 @@ int main(int argc, char* argv[])

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

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

std::this_thread::sleep_for(std::chrono::seconds(2));

std::string script_code = "zero_ftsensor()";

auto program_with_newline = script_code + '\n';

size_t len = program_with_newline.size();
const uint8_t* data = reinterpret_cast<const uint8_t*>(program_with_newline.c_str());
size_t written;

primary_stream.write(data, len, written);

// Package contents will be printed while not being interrupted
// Note: Packages for which the parsing isn't implemented, will only get their raw bytes printed.
while (true)
Expand Down
2 changes: 2 additions & 0 deletions include/ur_client_library/comm/producer.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class URProducer : public IProducer<T>
{
}

virtual ~URProducer() = default;

/*!
* \brief Triggers the stream to connect to the robot.
*/
Expand Down
17 changes: 14 additions & 3 deletions include/ur_client_library/primary/abstract_primary_consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@
*/
//----------------------------------------------------------------------

#ifndef UR_ROBOT_DRIVER_ABSTRACT_PRIMARY_CONSUMER_H_INCLUDED
#define UR_ROBOT_DRIVER_ABSTRACT_PRIMARY_CONSUMER_H_INCLUDED
#ifndef UR_CLIENT_LIBRARY_ABSTRACT_PRIMARY_CONSUMER_H_INCLUDED
#define UR_CLIENT_LIBRARY_ABSTRACT_PRIMARY_CONSUMER_H_INCLUDED

#include "ur_client_library/log.h"
#include "ur_client_library/comm/pipeline.h"
#include "ur_client_library/primary/robot_message/error_code_message.h"
#include "ur_client_library/primary/robot_message/key_message.h"
#include "ur_client_library/primary/robot_message/runtime_exception_message.h"
#include "ur_client_library/primary/robot_message/text_message.h"
#include "ur_client_library/primary/robot_message/version_message.h"
#include "ur_client_library/primary/robot_state/kinematics_info.h"
#include "ur_client_library/primary/program_state_message/global_variables_update_message.h"

namespace urcl
{
Expand Down Expand Up @@ -70,13 +75,19 @@ class AbstractPrimaryConsumer : public comm::IConsumer<PrimaryPackage>
// To be implemented in specific consumers
virtual bool consume(RobotMessage& pkg) = 0;
virtual bool consume(RobotState& pkg) = 0;
virtual bool consume(ErrorCodeMessage& pkg) = 0;
virtual bool consume(KeyMessage& pkg) = 0;
virtual bool consume(RuntimeExceptionMessage& pkg) = 0;
virtual bool consume(TextMessage& pkg) = 0;
virtual bool consume(VersionMessage& pkg) = 0;
virtual bool consume(KinematicsInfo& pkg) = 0;
virtual bool consume(ProgramStateMessage& pkg) = 0;
virtual bool consume(GlobalVariablesUpdateMessage& pkg) = 0;

private:
/* data */
};
} // namespace primary_interface
} // namespace urcl

#endif // ifndef UR_ROBOT_DRIVER_ABSTRACT_PRIMARY_CONSUMER_H_INCLUDED
#endif // ifndef UR_CLIENT_LIBRARY_ABSTRACT_PRIMARY_CONSUMER_H_INCLUDED
95 changes: 95 additions & 0 deletions include/ur_client_library/primary/error_code_message_handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
//
// -- BEGIN LICENSE BLOCK ----------------------------------------------
// Copyright 2020 FZI Forschungszentrum Informatik
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -- END LICENSE BLOCK ------------------------------------------------

//----------------------------------------------------------------------
/*!\file
*
* \author Felix Exner [email protected]
* \date 2020-04-30
*
*/
//----------------------------------------------------------------------

#ifndef UR_CLIENT_LIBRARY_ERROR_CODE_MESSAGE_HANDLER_H_INCLUDED
#define UR_CLIENT_LIBRARY_ERROR_CODE_MESSAGE_HANDLER_H_INCLUDED

#include <ur_client_library/log.h>
#include <ur_client_library/primary/primary_package_handler.h>
#include <ur_client_library/primary/robot_message/error_code_message.h>

namespace urcl
{
namespace primary_interface
{
class ErrorCodeMessageHandler : public IPrimaryPackageHandler<ErrorCodeMessage>
{
public:
ErrorCodeMessageHandler() = default;
virtual ~ErrorCodeMessageHandler() = default;

/*!
* \brief Actual worker function
*
* \param pkg package that should be handled
*/
virtual void handle(ErrorCodeMessage& pkg) override
{
std::stringstream out_ss;
out_ss << "---ErrorCodeMessage---\n" << pkg.toString().c_str() << std::endl;
switch (pkg.report_level_)
{
case ReportLevel::DEBUG:
case ReportLevel::DEVL_DEBUG:
{
LOG_DEBUG("%s", out_ss.str().c_str());
break;
}
case ReportLevel::INFO:
case ReportLevel::DEVL_INFO:
{
LOG_INFO("%s", out_ss.str().c_str());
break;
}
case ReportLevel::WARNING:
{
LOG_WARN("%s", out_ss.str().c_str());
break;
}
case ReportLevel::VIOLATION:
case ReportLevel::FAULT:
case ReportLevel::DEVL_VIOLATION:
case ReportLevel::DEVL_FAULT:
{
LOG_ERROR("%s", out_ss.str().c_str());
break;
}
default:
{
std::stringstream ss;
ss << "Unknown report level: " << static_cast<int>(pkg.report_level_) << std::endl << out_ss.str();
LOG_ERROR("%s", ss.str().c_str());
}
}
}

private:
/* data */
};
} // namespace primary_interface
} // namespace urcl
#endif // ifndef UR_CLIENT_LIBRARY_ERROR_CODE_MESSAGE_HANDLER_H_INCLUDED
60 changes: 60 additions & 0 deletions include/ur_client_library/primary/key_message_handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
//
// -- BEGIN LICENSE BLOCK ----------------------------------------------
// Copyright 2020 FZI Forschungszentrum Informatik
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -- END LICENSE BLOCK ------------------------------------------------

//----------------------------------------------------------------------
/*!\file
*
* \author Felix Exner [email protected]
* \date 2020-04-30
*
*/
//----------------------------------------------------------------------

#ifndef UR_CLIENT_LIBRARY_KEY_MESSAGE_HANDLER_H_INCLUDED
#define UR_CLIENT_LIBRARY_KEY_MESSAGE_HANDLER_H_INCLUDED

#include <ur_client_library/log.h>
#include <ur_client_library/primary/primary_package_handler.h>
#include <ur_client_library/primary/robot_message/key_message.h>

namespace urcl
{
namespace primary_interface
{
class KeyMessageHandler : public IPrimaryPackageHandler<KeyMessage>
{
public:
KeyMessageHandler() = default;
virtual ~KeyMessageHandler() = default;

/*!
* \brief Actual worker function
*
* \param pkg package that should be handled
*/
virtual void handle(KeyMessage& pkg) override
{
LOG_INFO("---KeyMessage---\n%s", pkg.toString().c_str());
}

private:
/* data */
};
} // namespace primary_interface
} // namespace urcl
#endif // ifndef UR_CLIENT_LIBRARY_KEY_MESSAGE_HANDLER_H_INCLUDED
79 changes: 79 additions & 0 deletions include/ur_client_library/primary/primary_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-

// -- BEGIN LICENSE BLOCK ----------------------------------------------
// Copyright 2019 FZI Forschungszentrum Informatik
//
// Licensed under the Apache License, Text 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -- END LICENSE BLOCK ------------------------------------------------

//----------------------------------------------------------------------
/*!\file
*
* \author Felix Exner [email protected]
* \date 2020-04-30
*
*/
//----------------------------------------------------------------------
#ifndef UR_CLIENT_LIBRARY_PRIMARY_CLIENT_H_INCLUDED
#define UR_CLIENT_LIBRARY_PRIMARY_CLIENT_H_INCLUDED

#include <ur_client_library/primary/primary_parser.h>
#include <ur_client_library/comm/producer.h>
#include <ur_client_library/comm/stream.h>
#include <ur_client_library/comm/pipeline.h>
#include <ur_client_library/ur/calibration_checker.h>
#include <ur_client_library/primary/primary_consumer.h>

namespace urcl
{
namespace primary_interface
{
class PrimaryClient
{
public:
PrimaryClient() = delete;
PrimaryClient(const std::string& robot_ip, const std::string& calibration_checksum);
virtual ~PrimaryClient() = default;

/*!
* \brief Sends a custom script program to the robot.
*
* The given code must be valid according the UR Scripting Manual.
*
* \param script_code URScript code that shall be executed by the robot.
*
* \returns true on successful upload, false otherwise.
*/
bool sendScript(const std::string& script_code);

/*!
* \brief Checks if the kinematics information in the used model fits the actual robot.
*
* \param checksum Hash of the used kinematics information
*/
void checkCalibration(const std::string& checksum);

private:
std::string robot_ip_;
PrimaryParser parser_;
std::unique_ptr<PrimaryConsumer> consumer_;
comm::INotifier notifier_;
std::unique_ptr<comm::URProducer<PrimaryPackage>> producer_;
std::unique_ptr<comm::URStream<PrimaryPackage>> stream_;
std::unique_ptr<comm::Pipeline<PrimaryPackage>> pipeline_;
};

} // namespace primary_interface
} // namespace urcl

#endif // ifndef UR_CLIENT_LIBRARY_PRIMARY_CLIENT_H_INCLUDED
Loading