Go to the documentation of this file.00001
00002
00003
00004 #include <robotican_hardware_interface/Ultrasonic.h>
00005
00006 robotican_hardware::Ultrasonic::Ultrasonic(byte id, TransportLayer *transportLayer, byte pin, std::string topicName,
00007 std::string frameId, std::string sonarName)
00008 : Device(id, transportLayer) {
00009 _pin = pin;
00010 _topicName = topicName;
00011 _frameId = frameId;
00012
00013 if(sonarName == "Max_Sonar_LV") {
00014 _analog2Range = 127.0f / 9920.0f;
00015 } else if(sonarName == "Max_Sonar_HRLV") {
00016 _analog2Range = 128.0f / 25575.0f;
00017 }
00018 else {
00019 _analog2Range = 0.0;
00020 }
00021
00022 }
00023
00024 void robotican_hardware::Ultrasonic::update(const DeviceMessage *deviceMessage) {
00025 if(isReady()) {
00026 UltrasonicFeedback *feedback = (UltrasonicFeedback *) deviceMessage;
00027 uint16_t currentRead = feedback->currentRead;
00028
00029 sensor_msgs::Range range;
00030 range.header.frame_id = _frameId;
00031 range.header.stamp = ros::Time::now();
00032
00033 range.max_range = MAX_RANGE_URF_HRLV_MaxSonar;
00034 range.min_range = 0.20;
00035 range.field_of_view = FIELD_OF_VIEW_URF_HRLV_MaxSonar;
00036
00037 range.radiation_type = sensor_msgs::Range::ULTRASOUND;
00038
00039 range.range = (float) (currentRead * _analog2Range);
00040 _ultrasonicRead.publish(range);
00041 }
00042
00043 }
00044
00045 void robotican_hardware::Ultrasonic::write() {
00046
00047 }
00048
00049 void robotican_hardware::Ultrasonic::buildDevice() {
00050 BuildUltrasonic buildUltrasonic;
00051 buildUltrasonic.length = sizeof(buildUltrasonic);
00052 buildUltrasonic.checkSum = 0;
00053 buildUltrasonic.id = getId();
00054 buildUltrasonic.pin = _pin;
00055
00056 uint8_t *rawData = (uint8_t*)&buildUltrasonic;
00057 buildUltrasonic.checkSum = _transportLayer->calcChecksum(rawData, buildUltrasonic.length);
00058 _transportLayer->write(rawData, buildUltrasonic.length);
00059 }
00060
00061 void robotican_hardware::Ultrasonic::deviceAck(const DeviceAck *ack) {
00062 Device::deviceAck(ack);
00063 if(isReady()) {
00064 ros_utils::rosInfo("Ultrasonic is ready");
00065 _ultrasonicRead = _nodeHandle.advertise<sensor_msgs::Range>(_topicName, 10);
00066
00067 }
00068 else {
00069 ros_utils::rosError("RiCBoard can't build ultrasonic object for spme reason, this program will shut down now");
00070 ros::shutdown();
00071 }
00072 }