Pipe Inpection Robot / Mbed OS GPG_motor

Dependencies:   BufferedSerial sn7544

Fork of GPG_motor by Kang mingyo

Committer:
Jeonghoon
Date:
Thu Jun 27 04:58:29 2019 +0000
Revision:
7:13dd93a0efe8
combine motor with ROS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jeonghoon 7:13dd93a0efe8 1 /*
Jeonghoon 7:13dd93a0efe8 2 * Software License Agreement (BSD License)
Jeonghoon 7:13dd93a0efe8 3 *
Jeonghoon 7:13dd93a0efe8 4 * Copyright (c) 2011, Willow Garage, Inc.
Jeonghoon 7:13dd93a0efe8 5 * All rights reserved.
Jeonghoon 7:13dd93a0efe8 6 *
Jeonghoon 7:13dd93a0efe8 7 * Redistribution and use in source and binary forms, with or without
Jeonghoon 7:13dd93a0efe8 8 * modification, are permitted provided that the following conditions
Jeonghoon 7:13dd93a0efe8 9 * are met:
Jeonghoon 7:13dd93a0efe8 10 *
Jeonghoon 7:13dd93a0efe8 11 * * Redistributions of source code must retain the above copyright
Jeonghoon 7:13dd93a0efe8 12 * notice, this list of conditions and the following disclaimer.
Jeonghoon 7:13dd93a0efe8 13 * * Redistributions in binary form must reproduce the above
Jeonghoon 7:13dd93a0efe8 14 * copyright notice, this list of conditions and the following
Jeonghoon 7:13dd93a0efe8 15 * disclaimer in the documentation and/or other materials provided
Jeonghoon 7:13dd93a0efe8 16 * with the distribution.
Jeonghoon 7:13dd93a0efe8 17 * * Neither the name of Willow Garage, Inc. nor the names of its
Jeonghoon 7:13dd93a0efe8 18 * contributors may be used to endorse or promote prducts derived
Jeonghoon 7:13dd93a0efe8 19 * from this software without specific prior written permission.
Jeonghoon 7:13dd93a0efe8 20 *
Jeonghoon 7:13dd93a0efe8 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Jeonghoon 7:13dd93a0efe8 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Jeonghoon 7:13dd93a0efe8 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
Jeonghoon 7:13dd93a0efe8 24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
Jeonghoon 7:13dd93a0efe8 25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
Jeonghoon 7:13dd93a0efe8 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
Jeonghoon 7:13dd93a0efe8 27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Jeonghoon 7:13dd93a0efe8 28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Jeonghoon 7:13dd93a0efe8 29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Jeonghoon 7:13dd93a0efe8 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
Jeonghoon 7:13dd93a0efe8 31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Jeonghoon 7:13dd93a0efe8 32 * POSSIBILITY OF SUCH DAMAGE.
Jeonghoon 7:13dd93a0efe8 33 */
Jeonghoon 7:13dd93a0efe8 34
Jeonghoon 7:13dd93a0efe8 35 #ifndef ROS_SUBSCRIBER_H_
Jeonghoon 7:13dd93a0efe8 36 #define ROS_SUBSCRIBER_H_
Jeonghoon 7:13dd93a0efe8 37
Jeonghoon 7:13dd93a0efe8 38 #include "rosserial_msgs/TopicInfo.h"
Jeonghoon 7:13dd93a0efe8 39
Jeonghoon 7:13dd93a0efe8 40 namespace ros {
Jeonghoon 7:13dd93a0efe8 41
Jeonghoon 7:13dd93a0efe8 42 /* Base class for objects subscribers. */
Jeonghoon 7:13dd93a0efe8 43 class Subscriber_
Jeonghoon 7:13dd93a0efe8 44 {
Jeonghoon 7:13dd93a0efe8 45 public:
Jeonghoon 7:13dd93a0efe8 46 virtual void callback(unsigned char *data)=0;
Jeonghoon 7:13dd93a0efe8 47 virtual int getEndpointType()=0;
Jeonghoon 7:13dd93a0efe8 48
Jeonghoon 7:13dd93a0efe8 49 // id_ is set by NodeHandle when we advertise
Jeonghoon 7:13dd93a0efe8 50 int id_;
Jeonghoon 7:13dd93a0efe8 51
Jeonghoon 7:13dd93a0efe8 52 virtual const char * getMsgType()=0;
Jeonghoon 7:13dd93a0efe8 53 virtual const char * getMsgMD5()=0;
Jeonghoon 7:13dd93a0efe8 54 const char * topic_;
Jeonghoon 7:13dd93a0efe8 55 };
Jeonghoon 7:13dd93a0efe8 56
Jeonghoon 7:13dd93a0efe8 57 /* Bound function subscriber. */
Jeonghoon 7:13dd93a0efe8 58 template<typename MsgT, typename ObjT=void>
Jeonghoon 7:13dd93a0efe8 59 class Subscriber: public Subscriber_
Jeonghoon 7:13dd93a0efe8 60 {
Jeonghoon 7:13dd93a0efe8 61 public:
Jeonghoon 7:13dd93a0efe8 62 typedef void(ObjT::*CallbackT)(const MsgT&);
Jeonghoon 7:13dd93a0efe8 63 MsgT msg;
Jeonghoon 7:13dd93a0efe8 64
Jeonghoon 7:13dd93a0efe8 65 Subscriber(const char * topic_name, CallbackT cb, ObjT* obj, int endpoint=rosserial_msgs::TopicInfo::ID_SUBSCRIBER) :
Jeonghoon 7:13dd93a0efe8 66 cb_(cb),
Jeonghoon 7:13dd93a0efe8 67 obj_(obj),
Jeonghoon 7:13dd93a0efe8 68 endpoint_(endpoint)
Jeonghoon 7:13dd93a0efe8 69 {
Jeonghoon 7:13dd93a0efe8 70 topic_ = topic_name;
Jeonghoon 7:13dd93a0efe8 71 };
Jeonghoon 7:13dd93a0efe8 72
Jeonghoon 7:13dd93a0efe8 73 virtual void callback(unsigned char* data)
Jeonghoon 7:13dd93a0efe8 74 {
Jeonghoon 7:13dd93a0efe8 75 msg.deserialize(data);
Jeonghoon 7:13dd93a0efe8 76 (obj_->*cb_)(msg);
Jeonghoon 7:13dd93a0efe8 77 }
Jeonghoon 7:13dd93a0efe8 78
Jeonghoon 7:13dd93a0efe8 79 virtual const char * getMsgType() { return this->msg.getType(); }
Jeonghoon 7:13dd93a0efe8 80 virtual const char * getMsgMD5() { return this->msg.getMD5(); }
Jeonghoon 7:13dd93a0efe8 81 virtual int getEndpointType() { return endpoint_; }
Jeonghoon 7:13dd93a0efe8 82
Jeonghoon 7:13dd93a0efe8 83 private:
Jeonghoon 7:13dd93a0efe8 84 CallbackT cb_;
Jeonghoon 7:13dd93a0efe8 85 ObjT* obj_;
Jeonghoon 7:13dd93a0efe8 86 int endpoint_;
Jeonghoon 7:13dd93a0efe8 87 };
Jeonghoon 7:13dd93a0efe8 88
Jeonghoon 7:13dd93a0efe8 89 /* Standalone function subscriber. */
Jeonghoon 7:13dd93a0efe8 90 template<typename MsgT>
Jeonghoon 7:13dd93a0efe8 91 class Subscriber<MsgT, void>: public Subscriber_
Jeonghoon 7:13dd93a0efe8 92 {
Jeonghoon 7:13dd93a0efe8 93 public:
Jeonghoon 7:13dd93a0efe8 94 typedef void(*CallbackT)(const MsgT&);
Jeonghoon 7:13dd93a0efe8 95 MsgT msg;
Jeonghoon 7:13dd93a0efe8 96
Jeonghoon 7:13dd93a0efe8 97 Subscriber(const char * topic_name, CallbackT cb, int endpoint=rosserial_msgs::TopicInfo::ID_SUBSCRIBER) :
Jeonghoon 7:13dd93a0efe8 98 cb_(cb),
Jeonghoon 7:13dd93a0efe8 99 endpoint_(endpoint)
Jeonghoon 7:13dd93a0efe8 100 {
Jeonghoon 7:13dd93a0efe8 101 topic_ = topic_name;
Jeonghoon 7:13dd93a0efe8 102 };
Jeonghoon 7:13dd93a0efe8 103
Jeonghoon 7:13dd93a0efe8 104 virtual void callback(unsigned char* data)
Jeonghoon 7:13dd93a0efe8 105 {
Jeonghoon 7:13dd93a0efe8 106 msg.deserialize(data);
Jeonghoon 7:13dd93a0efe8 107 this->cb_(msg);
Jeonghoon 7:13dd93a0efe8 108 }
Jeonghoon 7:13dd93a0efe8 109
Jeonghoon 7:13dd93a0efe8 110 virtual const char * getMsgType() { return this->msg.getType(); }
Jeonghoon 7:13dd93a0efe8 111 virtual const char * getMsgMD5() { return this->msg.getMD5(); }
Jeonghoon 7:13dd93a0efe8 112 virtual int getEndpointType() { return endpoint_; }
Jeonghoon 7:13dd93a0efe8 113
Jeonghoon 7:13dd93a0efe8 114 private:
Jeonghoon 7:13dd93a0efe8 115 CallbackT cb_;
Jeonghoon 7:13dd93a0efe8 116 int endpoint_;
Jeonghoon 7:13dd93a0efe8 117 };
Jeonghoon 7:13dd93a0efe8 118
Jeonghoon 7:13dd93a0efe8 119 }
Jeonghoon 7:13dd93a0efe8 120
Jeonghoon 7:13dd93a0efe8 121 #endif