00001 // 00002 // Created by tom on 15/05/16. 00003 // 00004 00005 #include <robotican_hardware_interface/Gps.h> 00006 namespace robotican_hardware { 00007 Gps::Gps(byte id, TransportLayer *transportLayer, unsigned int baudrate, std::string topicName, 00008 std::string frameId) : Device(id, transportLayer) { 00009 _baudrate = baudrate; 00010 _frameId = frameId; 00011 _topicName = topicName; 00012 } 00013 00014 void Gps::update(const DeviceMessage *deviceMessage) { 00015 if(isReady()) { 00016 GpsFeedback *feedback = (GpsFeedback *) deviceMessage; 00017 sensor_msgs::NavSatFix msg; 00018 msg.header.frame_id = _frameId; 00019 msg.header.stamp = ros::Time::now(); 00020 msg.latitude = feedback->lat; 00021 msg.longitude = feedback->lng; 00022 msg.altitude = feedback->meters; 00023 msg.status.status = feedback->fix; 00024 msg.position_covariance[0] = feedback->HDOP * feedback->HDOP; 00025 msg.position_covariance[4] = feedback->HDOP * feedback->HDOP; 00026 msg.position_covariance[8] = feedback->HDOP * feedback->HDOP * 4; 00027 msg.status.service = 1; 00028 _gpsFeedback.publish(msg); 00029 } 00030 } 00031 00032 void Gps::write() { 00033 00034 } 00035 00036 void Gps::buildDevice() { 00037 BuildGps buildGps; 00038 buildGps.length = sizeof(buildGps); 00039 buildGps.checkSum = 0; 00040 buildGps.id = getId(); 00041 buildGps.baudrate = _baudrate; 00042 00043 uint8_t *rawData = (uint8_t *) &buildGps; 00044 buildGps.checkSum = _transportLayer->calcChecksum(rawData, buildGps.length); 00045 _transportLayer->write(rawData, buildGps.length); 00046 } 00047 00048 void Gps::deviceAck(const DeviceAck *ack) { 00049 Device::deviceAck(ack); 00050 if(isReady()) { 00051 ros_utils::rosInfo("Gps is ready"); 00052 _gpsFeedback = _nodeHandle.advertise<sensor_msgs::NavSatFix>(_topicName, 10); 00053 } 00054 else { 00055 ros_utils::rosError("RiCBoard can't build gps object for spme reason, this program will shut down now"); 00056 ros::shutdown(); 00057 } 00058 } 00059 }