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>
3130#include < ur_client_library/primary/primary_parser.h>
31+ #include < ur_client_library/primary/primary_client.h>
3232
3333using namespace urcl ;
3434
3535// In a real-world example it would be better to get those values from command line parameters / a better configuration
3636// system such as Boost.Program_options
3737const std::string DEFAULT_ROBOT_IP = " 192.168.56.101" ;
38+ const std::string CALIBRATION_CHECKSUM = " calib_12788084448423163542" ;
3839
3940int main (int argc, char * argv[])
4041{
41- // Set the loglevel to info get print out the DH parameters
4242 urcl::setLogLevel (urcl::LogLevel::INFO);
4343
4444 // Parse the ip arguments if given
@@ -48,40 +48,42 @@ int main(int argc, char* argv[])
4848 robot_ip = std::string (argv[1 ]);
4949 }
5050
51- // Parse how many seconds to run
52- int second_to_run = -1 ;
53- if (argc > 2 )
54- {
55- second_to_run = std::stoi (argv[2 ]);
56- }
57-
58- // First of all, we need a stream that connects to the robot
59- comm::URStream<primary_interface::PrimaryPackage> primary_stream (robot_ip, urcl::primary_interface::UR_PRIMARY_PORT);
60-
61- // This will parse the primary packages
62- primary_interface::PrimaryParser parser;
63-
64- // The producer needs both, the stream and the parser to fully work
65- comm::URProducer<primary_interface::PrimaryPackage> prod (primary_stream, parser);
66- prod.setupProducer ();
51+ // First of all, we need to create a primary client that connects to the robot
52+ primary_interface::PrimaryClient primary_client (robot_ip, CALIBRATION_CHECKSUM);
6753
68- // The shell consumer will print the package contents to the shell
69- std::unique_ptr<comm::IConsumer<primary_interface::PrimaryPackage>> consumer;
70- consumer.reset (new comm::ShellConsumer<primary_interface::PrimaryPackage>());
54+ // Give time to get the client to connect
55+ std::this_thread::sleep_for (std::chrono::milliseconds (1000 ));
7156
72- // The notifer will be called at some points during connection setup / loss. This isn't fully
73- // implemented atm.
74- comm::INotifier notifier;
75-
76- // Now that we have all components, we can create and start the pipeline to run it all.
77- comm::Pipeline<primary_interface::PrimaryPackage> pipeline (prod, consumer.get (), " Pipeline" , notifier);
78- pipeline.run ();
79-
80- // Package contents will be printed while not being interrupted
81- // Note: Packages for which the parsing isn't implemented, will only get their raw bytes printed.
82- do
57+ for (int i = 0 ; i < 10 ; ++i)
8358 {
84- std::this_thread::sleep_for (std::chrono::seconds (second_to_run));
85- } while (second_to_run < 0 );
59+ std::this_thread::sleep_for (std::chrono::milliseconds (1000 ));
60+ // Create script program to send through client
61+ std::stringstream cmd;
62+ cmd.imbue (std::locale::classic ()); // Make sure, decimal divider is actually '.'
63+ cmd << " sec setup():" << std::endl
64+ << " textmsg(\" Command through primary interface complete " << i++ << " \" )" << std::endl
65+ << " end" ;
66+ std::string script_code = cmd.str ();
67+ auto program_with_newline = script_code + ' \n ' ;
68+ // Send script
69+ primary_client.sendScript (program_with_newline);
70+
71+ try
72+ {
73+ URCL_LOG_INFO (" Cartesian Information:\n %s" , primary_client.getCartesianInfo ()->toString ().c_str ());
74+ URCL_LOG_INFO (" Calibration Hash:\n %s" , primary_client.getCalibrationChecker ()->getData ()->toHash ().c_str ());
75+ URCL_LOG_INFO (" Build Date:\n %s" , primary_client.getVersionMessage ()->build_date_ .c_str ());
76+ std::cout << primary_client.getJointData ()->toString () << std::endl;
77+ std::stringstream os;
78+ os << primary_client.getJointData ()->q_actual_ ;
79+ URCL_LOG_INFO (" Joint Angles:\n %s" , os.str ().c_str ());
80+ // getGlobalVariablesSetupMessage() will throw an exception if a program on the robot has not been started
81+ URCL_LOG_INFO (" Global Variables:\n %s" , primary_client.getGlobalVariablesSetupMessage ()->variable_names_ .c_str ());
82+ }
83+ catch (const UrException& e)
84+ {
85+ URCL_LOG_WARN (e.what ());
86+ }
87+ }
8688 return 0 ;
8789}
0 commit comments