complete motor

Dependencies:   BufferedSerial motor_sn7544

Committer:
Jeonghoon
Date:
Thu Nov 21 11:39:20 2019 +0000
Revision:
13:3ac8d2472417
Parent:
7:13dd93a0efe8
complete motor

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_SERVICE_CLIENT_H_
Jeonghoon 7:13dd93a0efe8 36 #define _ROS_SERVICE_CLIENT_H_
Jeonghoon 7:13dd93a0efe8 37
Jeonghoon 7:13dd93a0efe8 38 #include "rosserial_msgs/TopicInfo.h"
Jeonghoon 7:13dd93a0efe8 39
Jeonghoon 7:13dd93a0efe8 40 #include "ros/publisher.h"
Jeonghoon 7:13dd93a0efe8 41 #include "ros/subscriber.h"
Jeonghoon 7:13dd93a0efe8 42
Jeonghoon 7:13dd93a0efe8 43 namespace ros {
Jeonghoon 7:13dd93a0efe8 44
Jeonghoon 7:13dd93a0efe8 45 template<typename MReq , typename MRes>
Jeonghoon 7:13dd93a0efe8 46 class ServiceClient : public Subscriber_ {
Jeonghoon 7:13dd93a0efe8 47 public:
Jeonghoon 7:13dd93a0efe8 48 ServiceClient(const char* topic_name) :
Jeonghoon 7:13dd93a0efe8 49 pub(topic_name, &req, rosserial_msgs::TopicInfo::ID_SERVICE_CLIENT + rosserial_msgs::TopicInfo::ID_PUBLISHER)
Jeonghoon 7:13dd93a0efe8 50 {
Jeonghoon 7:13dd93a0efe8 51 this->topic_ = topic_name;
Jeonghoon 7:13dd93a0efe8 52 this->waiting = true;
Jeonghoon 7:13dd93a0efe8 53 }
Jeonghoon 7:13dd93a0efe8 54
Jeonghoon 7:13dd93a0efe8 55 virtual void call(const MReq & request, MRes & response)
Jeonghoon 7:13dd93a0efe8 56 {
Jeonghoon 7:13dd93a0efe8 57 if(!pub.nh_->connected()) return;
Jeonghoon 7:13dd93a0efe8 58 ret = &response;
Jeonghoon 7:13dd93a0efe8 59 waiting = true;
Jeonghoon 7:13dd93a0efe8 60 pub.publish(&request);
Jeonghoon 7:13dd93a0efe8 61 while(waiting && pub.nh_->connected())
Jeonghoon 7:13dd93a0efe8 62 if(pub.nh_->spinOnce() < 0) break;
Jeonghoon 7:13dd93a0efe8 63 }
Jeonghoon 7:13dd93a0efe8 64
Jeonghoon 7:13dd93a0efe8 65 // these refer to the subscriber
Jeonghoon 7:13dd93a0efe8 66 virtual void callback(unsigned char *data){
Jeonghoon 7:13dd93a0efe8 67 ret->deserialize(data);
Jeonghoon 7:13dd93a0efe8 68 waiting = false;
Jeonghoon 7:13dd93a0efe8 69 }
Jeonghoon 7:13dd93a0efe8 70 virtual const char * getMsgType(){ return this->resp.getType(); }
Jeonghoon 7:13dd93a0efe8 71 virtual const char * getMsgMD5(){ return this->resp.getMD5(); }
Jeonghoon 7:13dd93a0efe8 72 virtual int getEndpointType(){ return rosserial_msgs::TopicInfo::ID_SERVICE_CLIENT + rosserial_msgs::TopicInfo::ID_SUBSCRIBER; }
Jeonghoon 7:13dd93a0efe8 73
Jeonghoon 7:13dd93a0efe8 74 MReq req;
Jeonghoon 7:13dd93a0efe8 75 MRes resp;
Jeonghoon 7:13dd93a0efe8 76 MRes * ret;
Jeonghoon 7:13dd93a0efe8 77 bool waiting;
Jeonghoon 7:13dd93a0efe8 78 Publisher pub;
Jeonghoon 7:13dd93a0efe8 79 };
Jeonghoon 7:13dd93a0efe8 80
Jeonghoon 7:13dd93a0efe8 81 }
Jeonghoon 7:13dd93a0efe8 82
Jeonghoon 7:13dd93a0efe8 83 #endif