当前位置: 首页>>代码示例>>C++>>正文


C++ SerialPort::In方法代码示例

本文整理汇总了C++中SerialPort::In方法的典型用法代码示例。如果您正苦于以下问题:C++ SerialPort::In方法的具体用法?C++ SerialPort::In怎么用?C++ SerialPort::In使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SerialPort的用法示例。


在下文中一共展示了SerialPort::In方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SonarChipRead

/*!
 * \brief read from the chip
 * \param serial serial port object
 * \param timeout_mS communications timeout in milliseconds
 * \return true if successful
 */
bool SonarChipRead(
    SerialPort &serial,
    unsigned timeout_mS)
{
    sbuf[0] = I2C_CMD;
    sbuf[1] = 0x41;

    CurrentTransmissionType = TRANSMISSION_CHIP_READ;

    if (serial.In(sbuf, 3, timeout_mS) > 0)
        return true;
    else
        return false;
}
开发者ID:NIFTi-Fraunhofer,项目名称:nifti_uav,代码行数:20,代码来源:sonar.cpp

示例2: Update

/*!
 * \brief periodically ping each sensor
 * \param serial serial port object
 * \param timeout_mS communications timeout in milliseconds
 * \param range_mm array in which to store range data
 */
void Update(
    SerialPort &serial,
    unsigned timeout_mS,
    int *range_mm)
{
    ros::Time t = ros::Time::now();
    double time_since_last_ping_sec = (t - LastPinged).toSec();
    if ((time_since_last_ping_sec*1000 > ping_separation_mS) && (sensor_address == 0)) {
        // issue a ping
        PingNextSensor(serial, timeout_mS);
        LastPinged = t;
    }
    else {
        // read the time of flight or other returned value
        const int bytes = 4;
        unsigned char comBuffer[bytes];
        int returned_bytes = serial.In(comBuffer, bytes, timeout_mS);
        if (returned_bytes > 0) {

            unsigned char sensor_address = (unsigned char)(0xe0 + (sensor_index * 2));

            switch (CurrentTransmissionType)
            {
                case TRANSMISSION_PING: {
                    SonarChipWrite(serial, timeout_mS);
                    break;
                }
                case TRANSMISSION_CHIP_WRITE: {
                    SonarChipRead(serial, timeout_mS);
                    break;
                }
                case TRANSMISSION_CHIP_READ: {
                    break;
                }
                case TRANSMISSION_GAIN: {
                    SonarPing(serial, sensor_address, timeout_mS);
                    break;
                }
                case TRANSMISSION_SET_ADDRESS: {
                    ROS_INFO("Sensor address set");
                    SonarChipWrite(serial, timeout_mS);
                    transmission_complete = true;
                    break;
                }
                case TRANSMISSION_READ: {
                    if (returned_bytes > 2) {
                        unsigned int n = (unsigned int)(comBuffer[2] << 8);
                        if (returned_bytes > 3) n |= comBuffer[3];
                        int echo_uS = (int)n;
                        if (echo_uS > 0) {
                            range_mm[sensor_index] = n * 10 / 58;

                            // publish the range
                            usbi2c::sonar_params s;
                            s.index = sensor_index;
                            s.range_mm = range_mm[sensor_index];
			    s.stamp = ros::Time::now();
                            sonar_pub.publish(s);

			    // publish filtered range
			    sensor_msgs::Range sonar_height;
			    sonar_height.header.stamp = ros::Time::now();
			    sonar_height.header.frame_id = "uav_base_link";
			    sonar_height.radiation_type = 2;
			    sonar_height.field_of_view = 0.0;
			    sonar_height.min_range = -1000.0;
			    sonar_height.max_range = 1000.0;
			    sonar_height.range = cAFilter->run(outlierFilter->run(s.range_mm / 1000.0));
			    sonar_filtered_pub.publish(sonar_height);

                           //ROS_INFO("Sensor %d  Range mm %d", sensor_index, range_mm[sensor_index]);
                        }

                        // send gain limit
                        SonarGainLimit(serial, sensor_address, timeout_mS);
                    }
                    break;
                }
            }
        }
    }
}
开发者ID:NIFTi-Fraunhofer,项目名称:nifti_uav,代码行数:88,代码来源:sonar.cpp


注:本文中的SerialPort::In方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。