Skip to main content
. 2021 Mar 9;21(5):1915. doi: 10.3390/s21051915
Algorithm 2 PC Application
  • 1:

    functionSerial_Port_Enumeration(vector<string> &devices_name)

  • 2:

        detected_serial_portsgettheports_list                ▹ ROS serial lib is used

  • 3:

        PortFilter1"ttyUSB"

  • 4:

        PortFilter2"ttyACM"

  • 5:

        while detected_serial_ports is not ended do

  • 6:

            serial_portgetSerialPortfromdetected_serial_ports

  • 7:

            if serial_portbelongstotheclassofPortFilter1andPortFilter2 then

  • 8:

               add serial_porttodevices_name

  • 9:

            end if

  • 10:

        end while

  • 11:

        return number of found devices

  • 12:

    end function

  • 13:

    proceduresensor_init

  • 14:

        k0

  • 15:

        SensorIdx0

  • 16:

        SpNumSerial_Port_Enumeration(devices_name)

  • 17:

        if SpNumequalsto0 then

  • 18:

            return with error

  • 19:

        else

  • 20:

            for k1 to SpNum do

  • 21:

               Open devices_name.at(SpNum)

  • 22:

               Write b on devices_name.at(SpNum)

  • 23:

               SensorIDReadSensorIDfromdevices_name.at(SpNum)

  • 24:

               if a valid SensorID is received then

  • 25:

                   SensorList.at(SensorIdx).NameSensorID

  • 26:

                   SensorList.at(SensorIdx).SerialPortdevices_name.at(SpNum)

  • 27:

                   SensorList.at(SensorIdx).IdxSensorIdx

  • 28:

                   SensorIdxSensorIdx+1

  • 29:

               end if

  • 30:

               Close devices_name.at(SpNum)

  • 31:

            end for

  • 32:

        end if

  • 33:

    end procedure

  • 34:

    procedureuser_sensor_selection(SensorList)

  • 35:

        Print on screen the SensorList

  • 36:

        UserSensorIdxgettheuserselectionfromkeyboard

  • 37:

        Open Serial Port SensorList.at(UserSensorIdx).Name

  • 38:

        Write c on SensorList.at(UserSensorIdx).Name

  • 39:

        SensingElementsReadthenumberofsensingelementsfromSerialPort

  • 40:

        if SensingElements is equal to 0 then

  • 41:

            return with error

  • 42:

        else

  • 43:

            SensorList.at(UserSensorIdx).NumSensingElementsSensingElements

  • 44:

        end if

  • 45:

    end procedure

  • 46:

    procedureMain

  • 47:

        Set ROS Node name, ROS Topics name and ROS Node rate

  • 48:

        Call sensor_init

  • 49:

        Call user_sensor_selection

  • 50:

        MainLoop:

  • 51:

        Send a over SensorList.at(UserSensorIdx).SerialPort

  • 52:

        SensorList.at(UserSensorIdx).RawDatareadSensorDatafromSerial

  • 53:

        Send SensorList.at(UserSensorIdx).RawData over ROS Topic

  • 54:

        Wait for next iteration

  • 55:

        goto MainLoop

  • 56:

    end procedure