capstone_finish
Dependencies: BufferedSerial motor_sn7544
ros/service_client.h@10:ca4e4062701a, 2019-11-26 (annotated)
- Committer:
- Jeonghoon
- Date:
- Tue Nov 26 15:30:27 2019 +0000
- Revision:
- 10:ca4e4062701a
- Parent:
- 3:2a3664dc6634
capstone finish
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jeonghoon | 3:2a3664dc6634 | 1 | /* |
Jeonghoon | 3:2a3664dc6634 | 2 | * Software License Agreement (BSD License) |
Jeonghoon | 3:2a3664dc6634 | 3 | * |
Jeonghoon | 3:2a3664dc6634 | 4 | * Copyright (c) 2011, Willow Garage, Inc. |
Jeonghoon | 3:2a3664dc6634 | 5 | * All rights reserved. |
Jeonghoon | 3:2a3664dc6634 | 6 | * |
Jeonghoon | 3:2a3664dc6634 | 7 | * Redistribution and use in source and binary forms, with or without |
Jeonghoon | 3:2a3664dc6634 | 8 | * modification, are permitted provided that the following conditions |
Jeonghoon | 3:2a3664dc6634 | 9 | * are met: |
Jeonghoon | 3:2a3664dc6634 | 10 | * |
Jeonghoon | 3:2a3664dc6634 | 11 | * * Redistributions of source code must retain the above copyright |
Jeonghoon | 3:2a3664dc6634 | 12 | * notice, this list of conditions and the following disclaimer. |
Jeonghoon | 3:2a3664dc6634 | 13 | * * Redistributions in binary form must reproduce the above |
Jeonghoon | 3:2a3664dc6634 | 14 | * copyright notice, this list of conditions and the following |
Jeonghoon | 3:2a3664dc6634 | 15 | * disclaimer in the documentation and/or other materials provided |
Jeonghoon | 3:2a3664dc6634 | 16 | * with the distribution. |
Jeonghoon | 3:2a3664dc6634 | 17 | * * Neither the name of Willow Garage, Inc. nor the names of its |
Jeonghoon | 3:2a3664dc6634 | 18 | * contributors may be used to endorse or promote prducts derived |
Jeonghoon | 3:2a3664dc6634 | 19 | * from this software without specific prior written permission. |
Jeonghoon | 3:2a3664dc6634 | 20 | * |
Jeonghoon | 3:2a3664dc6634 | 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
Jeonghoon | 3:2a3664dc6634 | 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
Jeonghoon | 3:2a3664dc6634 | 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
Jeonghoon | 3:2a3664dc6634 | 24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
Jeonghoon | 3:2a3664dc6634 | 25 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
Jeonghoon | 3:2a3664dc6634 | 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
Jeonghoon | 3:2a3664dc6634 | 27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
Jeonghoon | 3:2a3664dc6634 | 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Jeonghoon | 3:2a3664dc6634 | 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
Jeonghoon | 3:2a3664dc6634 | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
Jeonghoon | 3:2a3664dc6634 | 31 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
Jeonghoon | 3:2a3664dc6634 | 32 | * POSSIBILITY OF SUCH DAMAGE. |
Jeonghoon | 3:2a3664dc6634 | 33 | */ |
Jeonghoon | 3:2a3664dc6634 | 34 | |
Jeonghoon | 3:2a3664dc6634 | 35 | #ifndef _ROS_SERVICE_CLIENT_H_ |
Jeonghoon | 3:2a3664dc6634 | 36 | #define _ROS_SERVICE_CLIENT_H_ |
Jeonghoon | 3:2a3664dc6634 | 37 | |
Jeonghoon | 3:2a3664dc6634 | 38 | #include "rosserial_msgs/TopicInfo.h" |
Jeonghoon | 3:2a3664dc6634 | 39 | |
Jeonghoon | 3:2a3664dc6634 | 40 | #include "ros/publisher.h" |
Jeonghoon | 3:2a3664dc6634 | 41 | #include "ros/subscriber.h" |
Jeonghoon | 3:2a3664dc6634 | 42 | |
Jeonghoon | 3:2a3664dc6634 | 43 | namespace ros { |
Jeonghoon | 3:2a3664dc6634 | 44 | |
Jeonghoon | 3:2a3664dc6634 | 45 | template<typename MReq , typename MRes> |
Jeonghoon | 3:2a3664dc6634 | 46 | class ServiceClient : public Subscriber_ { |
Jeonghoon | 3:2a3664dc6634 | 47 | public: |
Jeonghoon | 3:2a3664dc6634 | 48 | ServiceClient(const char* topic_name) : |
Jeonghoon | 3:2a3664dc6634 | 49 | pub(topic_name, &req, rosserial_msgs::TopicInfo::ID_SERVICE_CLIENT + rosserial_msgs::TopicInfo::ID_PUBLISHER) |
Jeonghoon | 3:2a3664dc6634 | 50 | { |
Jeonghoon | 3:2a3664dc6634 | 51 | this->topic_ = topic_name; |
Jeonghoon | 3:2a3664dc6634 | 52 | this->waiting = true; |
Jeonghoon | 3:2a3664dc6634 | 53 | } |
Jeonghoon | 3:2a3664dc6634 | 54 | |
Jeonghoon | 3:2a3664dc6634 | 55 | virtual void call(const MReq & request, MRes & response) |
Jeonghoon | 3:2a3664dc6634 | 56 | { |
Jeonghoon | 3:2a3664dc6634 | 57 | if(!pub.nh_->connected()) return; |
Jeonghoon | 3:2a3664dc6634 | 58 | ret = &response; |
Jeonghoon | 3:2a3664dc6634 | 59 | waiting = true; |
Jeonghoon | 3:2a3664dc6634 | 60 | pub.publish(&request); |
Jeonghoon | 3:2a3664dc6634 | 61 | while(waiting && pub.nh_->connected()) |
Jeonghoon | 3:2a3664dc6634 | 62 | if(pub.nh_->spinOnce() < 0) break; |
Jeonghoon | 3:2a3664dc6634 | 63 | } |
Jeonghoon | 3:2a3664dc6634 | 64 | |
Jeonghoon | 3:2a3664dc6634 | 65 | // these refer to the subscriber |
Jeonghoon | 3:2a3664dc6634 | 66 | virtual void callback(unsigned char *data){ |
Jeonghoon | 3:2a3664dc6634 | 67 | ret->deserialize(data); |
Jeonghoon | 3:2a3664dc6634 | 68 | waiting = false; |
Jeonghoon | 3:2a3664dc6634 | 69 | } |
Jeonghoon | 3:2a3664dc6634 | 70 | virtual const char * getMsgType(){ return this->resp.getType(); } |
Jeonghoon | 3:2a3664dc6634 | 71 | virtual const char * getMsgMD5(){ return this->resp.getMD5(); } |
Jeonghoon | 3:2a3664dc6634 | 72 | virtual int getEndpointType(){ return rosserial_msgs::TopicInfo::ID_SERVICE_CLIENT + rosserial_msgs::TopicInfo::ID_SUBSCRIBER; } |
Jeonghoon | 3:2a3664dc6634 | 73 | |
Jeonghoon | 3:2a3664dc6634 | 74 | MReq req; |
Jeonghoon | 3:2a3664dc6634 | 75 | MRes resp; |
Jeonghoon | 3:2a3664dc6634 | 76 | MRes * ret; |
Jeonghoon | 3:2a3664dc6634 | 77 | bool waiting; |
Jeonghoon | 3:2a3664dc6634 | 78 | Publisher pub; |
Jeonghoon | 3:2a3664dc6634 | 79 | }; |
Jeonghoon | 3:2a3664dc6634 | 80 | |
Jeonghoon | 3:2a3664dc6634 | 81 | } |
Jeonghoon | 3:2a3664dc6634 | 82 | |
Jeonghoon | 3:2a3664dc6634 | 83 | #endif |