{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "32ae0be7-5992-476f-ad74-e56705746f14", "metadata": {}, "outputs": [], "source": [ "! ../scripts/generate_cling_3rd_party.py roscpp" ] }, { "cell_type": "code", "execution_count": null, "id": "3ac2de29-2628-459a-9579-cdd8fd24f8c5", "metadata": {}, "outputs": [], "source": [ "! ../scripts/generate_cling_3rd_party.py roscpp_tutorials" ] }, { "cell_type": "code", "execution_count": null, "id": "599149ab-5807-422f-8ea9-7cbd9cbe86b1", "metadata": {}, "outputs": [], "source": [ "#include \"load_roscpp.h\"\n", "#include \"load_roscpp_tutorials.h\"" ] }, { "cell_type": "markdown", "id": "3d65d573-6b8b-4953-b141-f86696c2ace0", "metadata": {}, "source": [ "Code below are taken from http://wiki.ros.org/ROS/Tutorials/WritingServiceClient%28c%2B%2B%29" ] }, { "cell_type": "code", "execution_count": null, "id": "56bceb25-ebaf-4214-8166-ff9e0d73c501", "metadata": {}, "outputs": [], "source": [ "#include \n", "#include \n", "#include " ] }, { "cell_type": "code", "execution_count": null, "id": "de4077bd-7651-4327-87ea-8ec7d046e7e5", "metadata": {}, "outputs": [], "source": [ "bool add(roscpp_tutorials::TwoInts::Request &req,\n", " roscpp_tutorials::TwoInts::Response &res)\n", "{\n", " res.sum = req.a + req.b;\n", " ROS_INFO(\"request: x=%ld, y=%ld\", (long int)req.a, (long int)req.b);\n", " ROS_INFO(\"sending back response: [%ld]\", (long int)res.sum);\n", " return true;\n", "}" ] }, { "cell_type": "code", "execution_count": null, "id": "b4db6c4e-b2e1-41ca-9d82-a34ff76bfb4e", "metadata": {}, "outputs": [], "source": [ "int argc = 1;\n", "char *argv[1];\n", "argv[0] = new char[10];\n", "strcpy(argv[0], \"srv_server\");\n", "ros::init(argc, argv, \"srv_server\");\n", "\n", "ros::NodeHandle n;\n", "ros::ServiceServer service = n.advertiseService(\"add_two_ints\", add);\n", "std::cout<<\"Ready to add two ints.\\n\";\n", "ros::spin();" ] } ], "metadata": { "kernelspec": { "display_name": "C++17", "language": "C++17", "name": "xcpp17" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".cpp", "mimetype": "text/x-c++src", "name": "c++", "version": "17" } }, "nbformat": 4, "nbformat_minor": 5 }