Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BcbBattery #749

Merged
merged 6 commits into from
May 26, 2021
Merged

BcbBattery #749

merged 6 commits into from
May 26, 2021

Conversation

randaz81
Copy link
Member

@randaz81 randaz81 commented May 21, 2021

Some changes to: #727

Main changes and explanation:
I did some experiments and I noticed that the previous implementation was too much dependent on the thread period: a wrong value could cause severe misbehavior.

  • If the thread period was too small, not enough characters were received in the internal buffer. So all the receiver_character() calls become blocking for the number of milliseconds specified in the configuration file (default = 5ms)
  • If the thread period was too large, many packets (i.e. blocks of 10 bytes) were placed in the buffer, but the parsing function was just getting the first (old) one. I added a flush() to avoid that the buffer increases in size indefinitely, however, I still was not happy with the solution.

So: this is the logic of the new version:
On every run() cycle I copy all the content of the serial buffer to a local buffer and I search for the last (most recent) valid packet occurrence. This solution works as long as the thread period is at least twice the size of the duration of a packet (but I think that keeping it large, i.e. 500-1000ms is still a good idea)

@randaz81 randaz81 requested a review from pattacini May 21, 2021 15:18
@randaz81 randaz81 force-pushed the bcbBattery2 branch 3 times, most recently from 76a654a to 35a711a Compare May 21, 2021 15:22
@pattacini pattacini requested a review from S-Dafarra May 21, 2021 15:25
Copy link
Contributor

@S-Dafarra S-Dafarra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also like to run a test on iCubGenova04 first, if you don't mind.

@S-Dafarra
Copy link
Contributor

S-Dafarra commented May 21, 2021

I tried on iCubGenova04. I just cherry-picked the commit and applied on the version currently installed on the head (to avoid having to update the robot firmware), but I obtained the following output:

Click to expand
icub@icub-head:/usr/local/src/robot/robotology-superbuild/src/robots-configuration/iCubGenova04/battery (devel_iCubGenova04)$ yarprobotinterface --config icub_battery.xml 
[DEBUG] Reading file /usr/local/src/robot/robotology-superbuild/src/robots-configuration/iCubGenova04/battery/icub_battery.xml
[INFO] |yarp.os.Port| Port /log/icub-head/yarprobotinterface/3726 active at tcp://10.0.0.2:10169/
[DEBUG] yarprobotinterface: using xml parser for DTD v3.x
[DEBUG] Reading file /usr/local/src/robot/robotology-superbuild/src/robots-configuration/iCubGenova04/battery/icub_battery.xml
[DEBUG] Preprocessor complete in:  0.000133276 s
[INFO] |yarp.os.Port| Port /battery/yarprobotinterface active at tcp://10.0.0.2:10166/
[INFO] startup phase starting...
[INFO] |yarp.devices.BatteryWrapper| Using period: 0.1 s
[INFO] |yarp.os.Port| Port /icub/battery/data:o active at tcp://10.0.0.2:10167/
[INFO] |yarp.os.Port| Port /icub/battery/rpc:i active at tcp://10.0.0.2:10168/
[INFO] |yarp.dev.PolyDriver| Created wrapper <batteryWrapper>. See C++ class BatteryWrapper for documentation.
[DEBUG] (GENERAL (name icub_battery) (thread_period 100) (screen 1) (verbose 1) (debug 0) (silence_sync_warnings 1)) (SERIAL_PORT (verbose 1) (comport "/dev/rfcomm0") (baudrate 115200) (xonlim 0) (xofflim 0) (readmincharacters 0) (readtimeoutmsec 5) (parityenb 0) (paritymode none) (ctsenb 0) (rtsenb 0) (xinenb 0) (xoutenb 0) (modem 0) (rcvenb 0) (dsrenb 0) (dtrdisable 0) (databits 8) (stopbits 1) (line_terminator_char1 10) (line_terminator_char2 10)) (device bcbBattery) (robotName battery)
[INFO] |yarp.device.serialport| Starting Serial Port in /dev/rfcomm0 
[INFO] |yarp.dev.PolyDriver| Created device <serialport>. See C++ class SerialDeviceDriver for documentation.
[INFO] BcbBattery starting transmission
[DEBUG] |yarp.device.serialport| Sending string: ����`
[INFO] BcbBattery started successfully
[INFO] |yarp.dev.PolyDriver| Created device <bcbBattery>. See C++ class BcbBattery for documentation.
[INFO] Entering action level 5 of phase startup
[INFO] icubBattery is not an IWrapper. Trying IMultipleWrapper
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[INFO] All actions for action level 5 of startup phase started. Waiting for unfinished actions.
[INFO] All actions for action level 5 of startup phase finished.
[INFO] startup phase finished.
[INFO] run phase starting...
[DEBUG] yarprobotinterface running happily
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
^C[INFO] |yarp.os.RFModule| [try 1 of 3] Trying to shut down.
[WARNING] Interrupt # 1 # received.
[INFO] Interrupt received. Stopping all running threads.
[ERROR] |yarp.devices.BatteryWrapper| BatteryWrapper: : Sensor returned error
[INFO] |yarp.os.RFModule| RFModule closing.
[INFO] interrupt1 phase starting...
[INFO] interrupt1 phase finished.
[INFO] shutdown phase starting...
[INFO] Entering action level 5 of phase shutdown
[INFO] All actions for action level 5 of shutdown phase started. Waiting for unfinished actions.
[INFO] All actions for action level 5 of shutdown phase finished.
^C[INFO] |yarp.os.RFModule| [try 2 of 3] Trying to shut down.
[WARNING] Interrupt # 2 # received.
[INFO] Interrupt received. Stopping all running threads.
[INFO] interrupt2 phase starting...
[INFO] interrupt2 phase finished.
^C[INFO] |yarp.os.RFModule| [try 3 of 3] Trying to shut down.
[WARNING] Interrupt # 3 # received.
[INFO] Interrupt received. Stopping all running threads.
[INFO] interrupt3 phase starting...
[INFO] interrupt3 phase finished.
^C[INFO] |yarp.os.RFModule| Aborting (calling abort())...
Aborted (core dumped)

Apparently I was not able to close it cleanly, and I had to kill it.
The errors instead are probably related to another version of yarp, am I correct? What would be the necessary version? At the moment we are using yarp 3.4.

Just for reference, this is the output with the upstream version:

Click to expand
[DEBUG] Reading file /usr/local/src/robot/robotology-superbuild/src/robots-configuration/iCubGenova04/battery/icub_battery.xml
[INFO] |yarp.os.Port| Port /log/icub-head/yarprobotinterface/1703 active at tcp://10.0.0.2:10165/
[DEBUG] yarprobotinterface: using xml parser for DTD v3.x
[DEBUG] Reading file /usr/local/src/robot/robotology-superbuild/src/robots-configuration/iCubGenova04/battery/icub_battery.xml
[DEBUG] Preprocessor complete in:  0.000593185 s
[INFO] |yarp.os.Port| Port /battery/yarprobotinterface active at tcp://10.0.0.2:10166/
[INFO] startup phase starting...
[INFO] |yarp.devices.BatteryWrapper| Using period: 0.1 s
[INFO] |yarp.os.Port| Port /icub/battery/data:o active at tcp://10.0.0.2:10167/
[INFO] |yarp.os.Port| Port /icub/battery/rpc:i active at tcp://10.0.0.2:10168/
[INFO] |yarp.dev.PolyDriver| Created wrapper <batteryWrapper>. See C++ class BatteryWrapper for documentation.
[DEBUG] (GENERAL (name icub_battery) (thread_period 100) (screen 1) (verbose 1) (debug 0) (silence_sync_warnings 1)) (SERIAL_PORT (verbose 1) (comport "/dev/rfcomm0") (baudrate 115200) (xonlim 0) (xofflim 0) (readmincharacters 0) (readtimeoutmsec 5) (parityenb 0) (paritymode none) (ctsenb 0) (rtsenb 0) (xinenb 0) (xoutenb 0) (modem 0) (rcvenb 0) (dsrenb 0) (dtrdisable 0) (databits 8) (stopbits 1) (line_terminator_char1 10) (line_terminator_char2 10)) (device bcbBattery) (robotName battery)
[INFO] |yarp.device.serialport| Starting Serial Port in /dev/rfcomm0 
[INFO] |yarp.dev.PolyDriver| Created device <serialport>. See C++ class SerialDeviceDriver for documentation.
[DEBUG] |yarp.device.serialport| Sending string: �
[DEBUG] BcbBattery::run() serial_buffer is: (hex) -- -- -- -- -- -- -- -- -- -- , (dec) --- --- --- --- --- --- --- --- --- --- 
[INFO] |yarp.dev.PolyDriver| Created device <bcbBattery>. See C++ class BcbBattery for documentation.
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.0A      0.0V   charge:   0.0%    time: Fri May 21 17:24:52 2021

[INFO] Entering action level 5 of phase startup
[INFO] icubBattery is not an IWrapper. Trying IMultipleWrapper
[INFO] All actions for action level 5 of startup phase started. Waiting for unfinished actions.
[INFO] All actions for action level 5 of startup phase finished.
[INFO] startup phase finished.
[INFO] run phase starting...
[DEBUG] yarprobotinterface running happily
[DEBUG] BcbBattery::run() serial_buffer is: (hex) -- -- -- -- -- -- -- -- -- -- , (dec) --- --- --- --- --- --- --- --- --- --- 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.0A      0.0V   charge:   0.0%    time: Fri May 21 17:24:52 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 A8 00 53 80 0D 0A , (dec) 000 157 158 002 168 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:52 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D D0 02 D0 00 54 80 0D 0A , (dec) 000 157 208 002 208 000 084 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  84.0%    time: Fri May 21 17:24:52 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 -- -- -- -- -- -- -- -- -- , (dec) 000 --- --- --- --- --- --- --- --- --- 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  84.0%    time: Fri May 21 17:24:52 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 53 80 0D 0A -- -- -- -- -- , (dec) 000 083 128 013 010 --- --- --- --- --- 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  84.0%    time: Fri May 21 17:24:52 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 A8 00 53 80 0D 0A , (dec) 000 157 158 002 168 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:52 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 A8 00 53 80 0D 0A , (dec) 000 157 158 002 168 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:52 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 08 00 53 80 0D 0A , (dec) 000 157 158 002 008 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.5A     40.4V   charge:  83.0%    time: Fri May 21 17:24:52 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:52 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D D0 02 D0 00 54 80 0D 0A , (dec) 000 157 208 002 208 000 084 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  84.0%    time: Fri May 21 17:24:53 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:53 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 A8 00 53 80 0D 0A , (dec) 000 157 158 002 168 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:53 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D D0 02 A8 00 54 80 0D 0A , (dec) 000 157 208 002 168 000 084 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  84.0%    time: Fri May 21 17:24:53 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D D0 02 D0 00 54 80 0D 0A , (dec) 000 157 208 002 208 000 084 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  84.0%    time: Fri May 21 17:24:53 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E -- -- -- -- -- -- -- , (dec) 000 157 158 --- --- --- --- --- --- --- 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  84.0%    time: Fri May 21 17:24:53 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 53 80 0D 0A -- -- -- -- -- , (dec) 000 083 128 013 010 --- --- --- --- --- 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  84.0%    time: Fri May 21 17:24:53 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:53 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:53 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 A8 00 53 80 0D 0A , (dec) 000 157 158 002 168 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:53 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 A8 00 53 80 0D 0A , (dec) 000 157 158 002 168 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:54 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D D0 02 D0 00 54 80 0D 0A , (dec) 000 157 208 002 208 000 084 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  84.0%    time: Fri May 21 17:24:54 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:54 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:54 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:54 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D D0 02 D0 00 54 80 0D 0A , (dec) 000 157 208 002 208 000 084 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  84.0%    time: Fri May 21 17:24:54 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 -- -- -- -- -- -- -- -- -- , (dec) 000 --- --- --- --- --- --- --- --- --- 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  84.0%    time: Fri May 21 17:24:54 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 53 80 0D 0A 00 -- -- -- -- , (dec) 000 083 128 013 010 000 --- --- --- --- 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  84.0%    time: Fri May 21 17:24:54 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 53 80 0D 0A -- -- -- -- -- , (dec) 000 083 128 013 010 --- --- --- --- --- 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  84.0%    time: Fri May 21 17:24:54 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:54 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 A8 00 53 80 0D 0A , (dec) 000 157 158 002 168 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:55 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:55 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:55 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 A8 00 53 80 0D 0A , (dec) 000 157 158 002 168 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:55 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:55 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:55 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 A8 00 53 80 0D 0A , (dec) 000 157 158 002 168 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:55 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) -- -- -- -- -- -- -- -- -- -- , (dec) --- --- --- --- --- --- --- --- --- --- 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:55 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D D0 02 A8 00 54 80 0D 0A , (dec) 000 157 208 002 168 000 084 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  84.0%    time: Fri May 21 17:24:55 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 A8 00 53 80 0D 0A , (dec) 000 157 158 002 168 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:55 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 F8 00 53 80 0D 0A , (dec) 000 157 158 002 248 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.8A     40.4V   charge:  83.0%    time: Fri May 21 17:24:56 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D D0 02 D0 00 54 80 0D 0A , (dec) 000 157 208 002 208 000 084 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  84.0%    time: Fri May 21 17:24:56 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:56 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D D0 02 D0 00 54 80 0D 0A , (dec) 000 157 208 002 208 000 084 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  84.0%    time: Fri May 21 17:24:56 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 A8 00 53 80 0D 0A , (dec) 000 157 158 002 168 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:56 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 A8 00 53 80 0D 0A , (dec) 000 157 158 002 168 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:56 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:56 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 A8 00 53 80 0D 0A , (dec) 000 157 158 002 168 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:56 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 -- -- -- -- -- -- -- -- -- , (dec) 000 --- --- --- --- --- --- --- --- --- 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:56 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 54 80 0D 0A 00 -- -- -- -- , (dec) 000 084 128 013 010 000 --- --- --- --- 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:56 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 53 80 0D 0A -- -- -- -- -- , (dec) 000 083 128 013 010 --- --- --- --- --- 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:57 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:57 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D D0 02 D0 00 54 80 0D 0A , (dec) 000 157 208 002 208 000 084 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  84.0%    time: Fri May 21 17:24:57 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D D0 02 D0 00 54 80 0D 0A , (dec) 000 157 208 002 208 000 084 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  84.0%    time: Fri May 21 17:24:57 2021

^C[INFO] |yarp.os.RFModule| [try 1 of 3] Trying to shut down.
[WARNING] Interrupt # 1 # received.
[INFO] Interrupt received. Stopping all running threads.
[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D D0 02 D0 00 54 80 0D 0A , (dec) 000 157 208 002 208 000 084 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  84.0%    time: Fri May 21 17:24:57 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:57 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:57 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:57 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:57 2021

[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 D0 00 53 80 0D 0A , (dec) 000 157 158 002 208 000 083 128 013 010 
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:57 2021

[INFO] |yarp.os.RFModule| RFModule closing.
[INFO] interrupt1 phase starting...
[INFO] interrupt1 phase finished.
[INFO] shutdown phase starting...
[INFO] Entering action level 5 of phase shutdown
[INFO] All actions for action level 5 of shutdown phase started. Waiting for unfinished actions.
[DEBUG] BcbBattery::run() serial_buffer is: (hex) 00 9D 9E 02 -- -- -- -- -- -- , (dec) 000 157 158 002 --- --- --- --- --- --- 
[INFO] All actions for action level 5 of shutdown phase finished.
[DEBUG] BcbBattery::run() log_buffer is: battery status:   +0.7A     40.4V   charge:  83.0%    time: Fri May 21 17:24:58 2021

[DEBUG] |yarp.device.serialport| Sending string: 
[INFO] shutdown phase finished.
[INFO] |yarp.os.RFModule| RFModule finished.

@randaz81
Copy link
Member Author

randaz81 commented May 22, 2021

I apologize for the time you already spent on the review. I pushed an update with some MAJOR changes. Especially the logic is (again) completely different. To improve the readability, I deleted some of your comments which I am 100% sure do not apply anymore.
I edited the original PR description to explain the new changes.

@robotology robotology deleted a comment from S-Dafarra May 22, 2021
@robotology robotology deleted a comment from S-Dafarra May 22, 2021
@robotology robotology deleted a comment from S-Dafarra May 22, 2021
@randaz81
Copy link
Member Author

The errors instead are probably related to another version of yarp, am I correct? What would be the necessary version? At the moment we are using yarp 3.4.

I think 3.4.4 or master.

@randaz81
Copy link
Member Author

randaz81 commented May 22, 2021

Some considerations for improving the transmission protocol (some changes to firmware are required @MrAndrea )
The current data packet is:
0 x x x x x x x \r \n
I'd suggest a modification to:
0 x x x x x x x C S \r \n
where:

  • C is a progressive counter (0-255)
  • S is the checksum of the previous bytes. e.g.
unsigned char calculateLRC(unsigned char *buf, unsigned int n)
{
 unsigned char checksum = 0;
 while(n>0)
 {
  checksum += *buf++;
  n--;
 }
 return ((~checksum) + 1);
}

Copy link
Member

@pattacini pattacini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @randaz81 for the insights!

A few comments:

  • Please, don't delete comments, but just mark them as resolved explaining why.
  • It's quite important to understand if we depend on yarp@3.4.4 or yarp@master since we're about to yield a new distro. If we depend on yarp@master, I'm afraid we have to postpone the PR. On the other hand, yarp@3.4.4 is totally ok. cc @Nicogene @traversaro. Anyway, yarp@3.4.4 has been delivered a few days ago so it's quite likely that it's the version required here.
  • Can you clarify if the module shuts down now smoothly? I think so but it wasn't 100% clear from your latest comments.

src/libraries/icubmod/bcbBattery/bcbBattery.cpp Outdated Show resolved Hide resolved
yDebug("BcbBattery::run() serial_buffer is: (hex) %s, (dec) %s", hexBuffer, decBuffer);
printf("internal buffer:");
for (size_t i = 0; i < recb; i++)
printf("%02X ", (unsigned int)(tmp_buff[i] & 0xFF));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, keep also the decimal printout, as it was before. This is useful to debug if the incoming values make sense without having to convert them from hexadecimal to decimal.

Copy link
Member Author

@randaz81 randaz81 May 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, the regex cannot fail, so a correct representation of the packet is always given in the subsequent hex representation of the packet (line ~173 of the latest commit) . In that debug print, decimal representation is no more useful since they match 1:1 with the values you can read from the interface...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still, we could have problems at the sender level. That has been useful on few occasions in the past.

src/libraries/icubmod/bcbBattery/bcbBattery.cpp Outdated Show resolved Hide resolved
//parse battery data
std::smatch match;
string stringbuf((char*)tmp_buff, recb);
bool b = std::regex_search(stringbuf, match, r_exp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is regex_search safe to be used given that the first char of the input string is supposed to be a \0 (given the communication protocol the BCB uses)?

I did not manage to find any indication about this, but in https://en.cppreference.com/w/cpp/regex/regex_search, one of the documented usages involves a null-terminated string. If the input string is converted into a C string, then it may cause false negatives I suppose. I don't know if this can be implementation-dependent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, I tested it and I haven't noticed any problem... But that was my machine, I really hope that that this is not implementation dependent!

src/libraries/icubmod/bcbBattery/bcbBattery.h Outdated Show resolved Hide resolved
src/libraries/icubmod/bcbBattery/bcbBattery.cpp Outdated Show resolved Hide resolved
@S-Dafarra
Copy link
Contributor

Some changes to: #727

Main changes and explanation:
I did some experiments and I noticed that the previous implementation was too much dependent on the thread period: a wrong value could cause severe misbehavior.

  • If the thread period was too small, not enough characters were received in the internal buffer. So all the receiver_character() calls become blocking for the number of milliseconds specified in the configuration file (default = 5ms)
  • If the thread period was too large, many packets (i.e. blocks of 10 bytes) were placed in the buffer, but the parsing function was just getting the first (old) one. I added a flush() to avoid that the buffer increases in size indefinitely, however, I still was not happy with the solution.

So: this is the logic of the new version:
On every run() cycle I copy all the content of the serial buffer to a local buffer and I search for the last (most recent) valid packet occurrence. This solution works as long as the thread period is at least twice the size of the duration of a packet (but I think that keeping it large, i.e. 500-1000ms is still a good idea)

Thanks for the insights. Could we solve this by simply adding a flush and by reducing the timeout?

@randaz81 randaz81 requested a review from S-Dafarra May 24, 2021 10:49
@randaz81
Copy link
Member Author

  • It's quite important to understand if we depend on yarp@3.4.4 or yarp@master since we're about to yield a new distro. If we depend on yarp@master, I'm afraid we have to postpone the PR. On the other hand, yarp@3.4.4 is totally ok. cc @Nicogene @traversaro. Anyway, yarp@3.4.4 has been delivered a few days ago so it's quite likely that it's the version required here.

@S-Dafarra @pattacini the correct tag is yarp@3.4.5, sorry for the mistake

@randaz81 randaz81 requested a review from pattacini May 24, 2021 13:16
Copy link
Member

@pattacini pattacini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@S-Dafarra @pattacini the correct tag is yarp@3.4.5, sorry for the mistake

Thanks @randaz81 👍🏻
Just awaiting the final confirmation from @Nicogene and/or @traversaro on this.

CI is fine, so as long as @S-Dafarra is ok with the current status, I'll be happy to squash'n'merge.

@traversaro
Copy link
Member

@S-Dafarra @pattacini the correct tag is yarp@3.4.5, sorry for the mistake

Thanks @randaz81 👍🏻
Just awaiting the final confirmation from @Nicogene and/or @traversaro on this.

Ok YARP v3.4.5 for me.

Copy link
Member

@Nicogene Nicogene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preface: I have no insight in this device.
These changes shouldn't require that find_package(YARP 3.4.5)? In that case could be a problem for the packets creations, since we have not the yarp 3.4.5 deb packets ready, and the GA that build the icub packets install yarp from packets.

@pattacini
Copy link
Member

pattacini commented May 24, 2021

These changes shouldn't require that find_package(YARP 3.4.5)?

We can put this requirement in the main CMakelists.txt file of icub-main, once we will agree on this.

since we have not the yarp 3.4.5 deb packets ready

My point was right to check if we can officially incorporate yarp@3.4.5 in the upcoming Distro 2021.05.
cc @drdanz

@randaz81
Copy link
Member Author

Preface: I have no insight in this device.
These changes shouldn't require that find_package(YARP 3.4.5)? In that case could be a problem for the packets creations, since we have not the yarp 3.4.5 deb packets ready, and the GA that build the icub packets install yarp from packets.

Just for extra clarity: yarp.3.4.5 is not required to compile this device. However, if you do not have yarp.3.4.5, the device will behave in erratic way at runtime, since there was a bug in the wrapper, which was fixed indeed in 3.4.5.

@Nicogene
Copy link
Member

My point was right to check if we can officially incorporate yarp@3.4.5 in the upcoming Distro 2021.05.

For this, I think we are out of time because we need to make the deb packets of yarp and upload them at least on Github. We can put the tag in the yml of the superbuild, but we cannot put the requirement in the CMakelists, unless someone manage to do the packets before 31/05

Just for extra clarity: yarp.3.4.5 is not required to compile this device. However, if you do not have yarp.3.4.5, the device will behave in erratic way at runtime, since there was a bug in the wrapper, which was fixed indeed in 3.4.5.

So in the actual state on devel/master does not work either for that bug?

@pattacini
Copy link
Member

pattacini commented May 24, 2021

I can see a couple of solutions then:

  • we wait a few days after 31/05; it already happened in the past that we delivered the first weeks of the month after the one we were supposed to stay in 😏
  • we deliver 2021.05 with the run-time bug that we can then fix up in the subsequent 2021.05.feat-01, which is expected to be out at the end of June to support the brand new robot. However, we usually don't provide binaries for feat distros so we'd need to discuss this.

How do you see that?

@S-Dafarra
Copy link
Contributor

I just tried it on the robot again, but there was an exception thrown by regex:

[DEBUG] Reading file /usr/local/src/robot/robotology-superbuild/src/robots-configuration/iCubGenova04/battery/icub_battery.xml
[INFO] |yarp.os.Port| Port /log/icub-head/yarprobotinterface/15061 active at tcp://10.0.0.2:10434/
[INFO] |yarp.os.impl.PortCoreOutputUnit| Sending output from /log/icub-head/yarprobotinterface/15061 to /yarplogger using fast_tcp
[DEBUG] yarprobotinterface: using xml parser for DTD v3.x
[DEBUG] Reading file /usr/local/src/robot/robotology-superbuild/src/robots-configuration/iCubGenova04/battery/icub_battery.xml
[DEBUG] Preprocessor complete in:  0.000793219 s
[INFO] |yarp.os.Port| Port /battery/yarprobotinterface active at tcp://10.0.0.2:10435/
[INFO] startup phase starting...
[INFO] |yarp.devices.BatteryWrapper| Using period: 0.1 s
[INFO] |yarp.os.Port| Port /icub/battery/data:o active at tcp://10.0.0.2:10436/
[INFO] |yarp.os.Port| Port /icub/battery/rpc:i active at tcp://10.0.0.2:10437/
[INFO] |yarp.dev.PolyDriver| Created wrapper <batteryWrapper>. See C++ class BatteryWrapper for documentation.
[DEBUG] (GENERAL (name icub_battery) (thread_period 100) (screen 1) (verbose 1) (debug 0) (silence_sync_warnings 1)) (SERIAL_PORT (verbose 1) (comport "/dev/rfcomm0") (baudrate 115200) (xonlim 0) (xofflim 0) (readmincharacters 0) (readtimeoutmsec 5) (parityenb 0) (paritymode none) (ctsenb 0) (rtsenb 0) (xinenb 0) (xoutenb 0) (modem 0) (rcvenb 0) (dsrenb 0) (dtrdisable 0) (databits 8) (stopbits 1) (line_terminator_char1 10) (line_terminator_char2 10)) (device bcbBattery) (robotName battery)
[INFO] |yarp.device.serialport| Starting Serial Port in /dev/rfcomm0 
[INFO] |yarp.dev.PolyDriver| Created device <serialport>. See C++ class SerialDeviceDriver for documentation.
terminate called after throwing an instance of 'std::regex_error'
  what():  Parenthesis is not closed.
Aborted (core dumped)

@randaz81
Copy link
Member Author

randaz81 commented May 24, 2021

terminate called after throwing an instance of 'std::regex_error'
what(): Parenthesis is not closed.

Wow, this is pretty weird. I cannot get this error. According to what I was able to find on google, the error says that the regex expression definition (line 59, .h file) is incomplete, but on my setup (Ubuntu 18.04.2, gcc 7.4.0) it works fine.
Indeed I am able to replicate your error only if I intentionally remove line 63.
Can you provide more details about your system?

PS: Tested successfully also on VS2019

@S-Dafarra
Copy link
Contributor

terminate called after throwing an instance of 'std::regex_error'
what(): Parenthesis is not closed.

Wow, this is pretty weird. I cannot get this error. According to what I was able to find on google, the error says that the regex expression definition (line 59, .h file) is incomplete, but on my setup (Ubuntu 18.04.2, gcc 7.4.0) it works fine.
Indeed I am able to replicate your error only if I intentionally remove line 63.
Can you provide more details about your system?

PS: Tested successfully also on VS2019

I tested it on the icub-head, which is running Ubuntu 18.04 with gcc 7.5.0. Since I did not want to update icub-main to avoid updating the firmware, I rebased the branch on top of the version currently used on the robot. For reference, I pushed it here https://github.com/S-Dafarra/icub-main/tree/bcbBattery2. I also did a small change to avoid the error mentioned in #749 (comment) to pop up. The configuration files are those of https://github.com/dic-iit/robots-configuration/tree/99b67b9fae708d1e3a470607b0fa5083e82ee0d6/iCubGenova04/battery

@randaz81
Copy link
Member Author

Can you do a test also on a different machine? In any case, tomorrow I'll be in lab and we can check icub head setup together.

@S-Dafarra
Copy link
Contributor

Can you do a test also on a different machine? In any case, tomorrow I'll be in lab and we can check icub head setup together.

I am pretty interested to have it working on the icub-head, as it is the main PC in which we use this device. I am not sure yet if I will in the lab tomorrow, but we can organize by different means.

@randaz81 randaz81 requested a review from S-Dafarra May 26, 2021 17:21
@pattacini
Copy link
Member

We're running a bit late, in agreement w/ @Nicogene we propose the following plan:

  • As soon as the tests @S-Dafarra has been doing are all passed we can merge in devel.
  • We won't enforce to rely on yarp@3.4.5 as there's no time to create packages; this is not a problem as we can still build the codebase successfully. The workaround would be just to build yarp@3.4.5. We could state this clearly in the Distro 2021.05 summary if this PR will land within the deadline.

Copy link
Contributor

@S-Dafarra S-Dafarra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works pretty well and closes smoothly now!

Here the output on the robot head

[DEBUG] Reading file /usr/local/src/robot/robotology-superbuild/src/robots-configuration/iCubGenova04/battery/icub_battery.xml
[INFO] |yarp.os.Port| Port /log/icub-head/yarprobotinterface/7269 active at tcp://10.0.0.2:10013/
[DEBUG] yarprobotinterface: using xml parser for DTD v3.x
[DEBUG] Reading file /usr/local/src/robot/robotology-superbuild/src/robots-configuration/iCubGenova04/battery/icub_battery.xml
[DEBUG] Preprocessor complete in:  0.00011611 s
[INFO] |yarp.os.Port| Port /battery/yarprobotinterface active at tcp://10.0.0.2:10003/
[INFO] startup phase starting...
[INFO] |yarp.devices.BatteryWrapper| Using period: 0.1 s
[INFO] |yarp.os.Port| Port /icub/battery/data:o active at tcp://10.0.0.2:10004/
[INFO] |yarp.os.Port| Port /icub/battery/rpc:i active at tcp://10.0.0.2:10005/
[INFO] |yarp.dev.PolyDriver| Created wrapper <batteryWrapper>. See C++ class BatteryWrapper for documentation.
[DEBUG] (GENERAL (name icub_battery) (thread_period 100) (screen 1) (verbose 1) (debug 0) (silence_sync_warnings 1)) (SERIAL_PORT (verbose 1) (comport "/dev/rfcomm0") (baudrate 115200) (xonlim 0) (xofflim 0) (readmincharacters 0) (readtimeoutmsec 5) (parityenb 0) (paritymode none) (ctsenb 0) (rtsenb 0) (xinenb 0) (xoutenb 0) (modem 0) (rcvenb 0) (dsrenb 0) (dtrdisable 0) (databits 8) (stopbits 1) (line_terminator_char1 10) (line_terminator_char2 10)) (device bcbBattery) (robotName battery)
[INFO] |yarp.device.serialport| Starting Serial Port in /dev/rfcomm0 
[INFO] |yarp.dev.PolyDriver| Created device <serialport>. See C++ class SerialDeviceDriver for documentation.
[INFO] BcbBattery starting transmission
[DEBUG] |yarp.device.serialport| Sending string: ����`
[INFO] BcbBattery started successfully
[DEBUG] Internal buffer: 
[INFO] |yarp.dev.PolyDriver| Created device <bcbBattery>. See C++ class BcbBattery for documentation.
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:57 2021

[INFO] Entering action level 5 of phase startup
[INFO] icubBattery is not an IWrapper. Trying IMultipleWrapper
[INFO] All actions for action level 5 of startup phase started. Waiting for unfinished actions.
[INFO] All actions for action level 5 of startup phase finished.
[INFO] startup phase finished.
[INFO] run phase starting...
[DEBUG] yarprobotinterface running happily
[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:57 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:57 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:58 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:58 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:58 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:58 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:58 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:58 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:58 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:58 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:58 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:58 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:59 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:59 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:59 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:59 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:59 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:59 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:59 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:59 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:59 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:29:59 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:30:00 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:    0.0V   +0.0A, charge:   0.0%,   time: Wed May 26 17:30:00 2021

[DEBUG] Internal buffer: 00 9D 9E 02 D0 00 53 80 0D 0A 
[DEBUG] Found: <00> (9D 9E) (02 D0) (00 53) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  83.0%,   time: Wed May 26 17:30:00 2021

[DEBUG] Internal buffer: 00 9D D0 02 D0 00 54 80 0D 0A 
[DEBUG] Found: <00> (9D D0) (02 D0) (00 54) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  84.0%,   time: Wed May 26 17:30:00 2021

[DEBUG] Internal buffer: 00 9D 9E 02 D0 00 53 80 0D 0A 
[DEBUG] Found: <00> (9D 9E) (02 D0) (00 53) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  83.0%,   time: Wed May 26 17:30:00 2021

[DEBUG] Internal buffer: 00 9D D0 02 D0 00 54 80 0D 0A 
[DEBUG] Found: <00> (9D D0) (02 D0) (00 54) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  84.0%,   time: Wed May 26 17:30:00 2021

[DEBUG] Internal buffer: 00 9D 9E 02 D0 00 53 80 0D 0A 
[DEBUG] Found: <00> (9D 9E) (02 D0) (00 53) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  83.0%,   time: Wed May 26 17:30:00 2021

[DEBUG] Internal buffer: 00 9D D0 
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  83.0%,   time: Wed May 26 17:30:00 2021

[DEBUG] Internal buffer: 02 D0 00 54 80 0D 0A 
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  83.0%,   time: Wed May 26 17:30:00 2021

[DEBUG] Internal buffer: 00 9D D0 02 D0 00 54 80 0D 0A 
[DEBUG] Found: <00> (9D D0) (02 D0) (00 54) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  84.0%,   time: Wed May 26 17:30:00 2021

[DEBUG] Internal buffer: 00 9D D0 02 D0 00 54 80 0D 0A 
[DEBUG] Found: <00> (9D D0) (02 D0) (00 54) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  84.0%,   time: Wed May 26 17:30:01 2021

[DEBUG] Internal buffer: 00 9D D0 02 D0 00 54 80 0D 0A 
[DEBUG] Found: <00> (9D D0) (02 D0) (00 54) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  84.0%,   time: Wed May 26 17:30:01 2021

[DEBUG] Internal buffer: 00 9D D0 02 D0 00 54 80 0D 0A 
[DEBUG] Found: <00> (9D D0) (02 D0) (00 54) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  84.0%,   time: Wed May 26 17:30:01 2021

[DEBUG] Internal buffer: 00 9D D0 02 D0 00 54 80 0D 0A 
[DEBUG] Found: <00> (9D D0) (02 D0) (00 54) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  84.0%,   time: Wed May 26 17:30:01 2021

[DEBUG] Internal buffer: 00 9D D0 02 A8 00 54 80 0D 0A 
[DEBUG] Found: <00> (9D D0) (02 A8) (00 54) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  84.0%,   time: Wed May 26 17:30:01 2021

[DEBUG] Internal buffer: 00 9D 9E 02 D0 00 53 80 0D 0A 
[DEBUG] Found: <00> (9D 9E) (02 D0) (00 53) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  83.0%,   time: Wed May 26 17:30:01 2021

[DEBUG] Internal buffer: 00 9D D0 02 D0 00 54 80 0D 0A 
[DEBUG] Found: <00> (9D D0) (02 D0) (00 54) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  84.0%,   time: Wed May 26 17:30:01 2021

[DEBUG] Internal buffer: 00 9D 9E 
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  84.0%,   time: Wed May 26 17:30:01 2021

[DEBUG] Internal buffer: 
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  84.0%,   time: Wed May 26 17:30:01 2021

[DEBUG] Internal buffer: 00 9D D0 02 D0 00 54 80 0D 0A 
[DEBUG] Found: <00> (9D D0) (02 D0) (00 54) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  84.0%,   time: Wed May 26 17:30:01 2021

[DEBUG] Internal buffer: 00 9D D0 02 D0 00 54 80 0D 0A 
[DEBUG] Found: <00> (9D D0) (02 D0) (00 54) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  84.0%,   time: Wed May 26 17:30:02 2021

[DEBUG] Internal buffer: 00 9D 9E 02 D0 00 53 80 0D 0A 
[DEBUG] Found: <00> (9D 9E) (02 D0) (00 53) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  83.0%,   time: Wed May 26 17:30:02 2021

[DEBUG] Internal buffer: 00 9D D0 02 A8 00 54 80 0D 0A 
[DEBUG] Found: <00> (9D D0) (02 A8) (00 54) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  84.0%,   time: Wed May 26 17:30:02 2021

[DEBUG] Internal buffer: 00 9D D0 02 D0 00 54 80 0D 0A 
[DEBUG] Found: <00> (9D D0) (02 D0) (00 54) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  84.0%,   time: Wed May 26 17:30:02 2021

[DEBUG] Internal buffer: 00 9D 9E 02 D0 00 53 80 0D 0A 
[DEBUG] Found: <00> (9D 9E) (02 D0) (00 53) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  83.0%,   time: Wed May 26 17:30:02 2021

^C[INFO] |yarp.os.RFModule| [try 1 of 3] Trying to shut down.
[WARNING] Interrupt # 1 # received.
[INFO] Interrupt received. Stopping all running threads.
[DEBUG] Internal buffer: 00 9D D0 02 D0 00 54 80 0D 0A 
[DEBUG] Found: <00> (9D D0) (02 D0) (00 54) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  84.0%,   time: Wed May 26 17:30:02 2021

[DEBUG] Internal buffer: 00 9D 9E 02 A8 00 53 80 0D 0A 
[DEBUG] Found: <00> (9D 9E) (02 A8) (00 53) (80) <0D 0A>
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  83.0%,   time: Wed May 26 17:30:02 2021

[INFO] |yarp.os.RFModule| RFModule closing.
[INFO] interrupt1 phase starting...
[INFO] interrupt1 phase finished.
[INFO] shutdown phase starting...
[INFO] Entering action level 5 of phase shutdown
[DEBUG] Internal buffer: 00 9D D0 02 D0 00 54 80 0D 0A 
[INFO] All actions for action level 5 of shutdown phase started. Waiting for unfinished actions.
[DEBUG] Found: <00> (9D D0) (02 D0) (00 54) (80) <0D 0A>
[INFO] All actions for action level 5 of shutdown phase finished.
[DEBUG] BcbBattery::run() log_buffer is:   40.4V   +0.7A, charge:  84.0%,   time: Wed May 26 17:30:02 2021

[DEBUG] |yarp.device.serialport| Sending string: 
[INFO] shutdown phase finished.
[INFO] |yarp.os.RFModule| RFModule finished.

@pattacini
Copy link
Member

pattacini commented May 26, 2021

It works pretty well and closes smoothly now!

Cool then 🎉
@S-Dafarra you might want to officially approve the PR.
I'll wait for the CI to complete and then merge it.

@S-Dafarra
Copy link
Contributor

S-Dafarra commented May 26, 2021

It works pretty well and closes smoothly now!

Cool then
@S-Dafarra you might want to officially approve the PR.
I'll wait for the CI to complete and then merge it.

That was the message I put when I approved 😁

@pattacini pattacini merged commit 433113f into robotology:devel May 26, 2021
@pattacini
Copy link
Member

@Nicogene

PR merged ✔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants