Robobot SVN version 1179: Difference between revisions

From Rsewiki
 
(One intermediate revision by the same user not shown)
Line 131: Line 131:
[[file:hbt_update_time.png | 500px]]
[[file:hbt_update_time.png | 500px]]


A load test shows that many subscriptions every millisecond will not cause send errors. The teensy_interface has logged these incoming messages. All subscriptions were with an interval of 1ms. It can be seen that this does not hold when there are seven message types all subscribed with a 1ms interval. The initial timestamp in seconds is when received in teensy_interface.
Time between "hbt" messages received by the "teensy_interface". Should be every 1ms.
 
A load test shows that many subscriptions every millisecond will not cause send errors. The teensy_interface has logged these incoming messages. All subscriptions were with an interval of 1ms. It can be seen that this does not hold. In this case, seven message types were subscribed to at a 1ms interval. The list below shows messages for 7ms. The initial timestamp in seconds is when received in teensy_interface.


     1742054300.0009 Rx ;74livn 0 0 0 0 0 0 0 0 1
     1742054300.0009 Rx ;74livn 0 0 0 0 0 0 0 0 1

Latest revision as of 20:48, 15 March 2025

Back to Robobot

Update note 15 Mar 2025, SVN version 1179

  • Changes to mqtt-client.py to stop using start-button and to avoid starting mqtt-client if it is already running.
  • Changes to ip_disp to use start button only
  • Changes to teensy_firmware_8 in an attempt to avoid untimely dataflow stop.

A load test shows that Teensy can submit at least 5000 messages per second. The teensy_interface can receive and log this load with an occasional up to 5ms delay (seen once in 20 seconds). The messages were published to MQTT typically within 0.1ms.

What to do

  • Changes to the "mqtt-client" are detailed below to allow for a selective merge with your version.

mqtt-client

cd ~/svn/robobot/mqtt_python
mv mqtt-client.py mqtt-client-yours.py
svn up

This will update these files:

mqtt-client.py (stop using start button and test for starting two versions)
sgpio.py       (stop using start button and better stop function)
ulog.py        (avoid crash during stop)
service        (better stop button handling and new process running function)

ip_disp

cd ~svn/robobot/ip_disp/build
svn up ..
make -j3

Teensy_firmware

cd ~svn/robobot/teensy_firmware_8
svn up
./compile
./upload

Power cycle

  • Press start button in 5 seconds
  • Wait for shut down
  • Press power button to restart

Changes in mqtt-client

  • mqtt client do no longer listen to start button (now reserved for ip_disp, that starts the mqtt-client)
  • new check to see if mqtt-client is running already
  • stop button now functional

In mqtt-client.py

  • line 44 setproctitle("mqtt-client") moved to __main__
  • __main__ (end of file) is modified to
  if __name__ == "__main__":
   if service.process_running("mqtt-client"):
     print("% mqtt-client is already running - terminating")
     print("%   if it is partially crashed in the background, then try:")
     print("%     pkill mqtt-client")
     print("%   or, if that fails use the most brutal kill")
     print("%     pkill -9 mqtt-client")
   else:
     # set title of process, so that it is not just called Python
     setproctitle("mqtt-client")
     print("% Starting")
     # where is the MQTT data server:
     service.setup('localhost') # localhost
     if service.connected:
       loop()
     service.terminate()
   print("% Main Terminated")
  • The press start button test is removed in the loop() function near "if state == 0:"
   e.g. change
     start = gpio.start() or service.args.now
   to
     start = True
   
   

In uservice.py

  • importing psutil
  • the runAlive function is modified to test stop button every 50ms, as
   def runAlive(self):
       loop = 0;
       while not self.stop:
       # tell interface that we are alive
       if loop % 10 == 0:
           service.send(service.topicCmd + "ti/alive",str(service.startTime))
           # print(f"% sent Alive {datetime.now()}")
       if gpio.test_stop_button():
           self.terminate()
       t.sleep(0.05)
       loop += 1
       
  • A new function to test if a process is running is added:
   def process_running(self, process_name):
       for process in psutil.process_iter(['pid', 'name']):
       if process.info['name'] == process_name:
           return True
       return False
       
  • better shut-down when pressing stop.
   sends (in function "def terminate(self)":
     ...
     edge.lineControl(0, 0) # make sure line control is off
     service.send(service.topicCmd + "ti/rc","0 0") # stop robot control loop
     service.send(service.topicCmd + "T0/stop","") # should not be needed


In sgpio.py

  • removed all references to gpio13 (the start button)
  • removed the "def start(self):" function
  • renamed the "def stop(self):" function to "def test_stop_button(self):"

In ulog.py

  • In the three functions starting with "def write..." a new test is added to avoid a crash during shutdown
   from uservice import service
   if not service.stop:
     # do the write
     ...

Changes in ip_disp

  • Listening to pin 13 only
  • Turning on LED 16 as red when start is pressed

Changes in teensy_interface

  • Not changed.

teensy_firmware_8

Teensy would stop all data subscriptions if there were too many (10) send errors.

This has now been changed so that it only happens if there are no incoming messages to Teensy.

Load test

Time between "hbt" messages received by the "teensy_interface". Should be every 1ms.

A load test shows that many subscriptions every millisecond will not cause send errors. The teensy_interface has logged these incoming messages. All subscriptions were with an interval of 1ms. It can be seen that this does not hold. In this case, seven message types were subscribed to at a 1ms interval. The list below shows messages for 7ms. The initial timestamp in seconds is when received in teensy_interface.

   1742054300.0009 Rx ;74livn 0 0 0 0 0 0 0 0 1
   1742054300.0009 Rx ;98lis 0 1 1 0 1 1 0.85 0.79
   1742054300.0010 Rx ;74ird 0.699 0.360 3561 5585 1
   1742054300.0010 Rx ;76gyro0 4.11987 -0.274658 1.09863 0
   1742054300.0011 Rx ;03hbt 1392.8120 122 1033 19.16 4 8 8.8 0.29 0
   1742054300.0011 Rx ;05time 1393113088 1 175 177 177 1003 2005 8.8
   1742054300.0012 Rx ;62# usb 1392.813 14 0 7505 136243 7505 0 660
   1742054300.0013 Rx ;74livn 0 0 0 0 0 0 0 0 1
   1742054300.0013 Rx ;98lis 0 1 1 0 1 1 0.85 0.79
   1742054300.0014 Rx ;57ird 0.700 0.361 3554 5573 1
   1742054300.0014 Rx ;01gyro0 0.122283 0.0782471 -0.042572 1
   1742054300.0015 Rx ;95hbt 1392.8131 122 1033 19.15 4 8 8.8 0.30 0
   1742054300.0026 Rx ;05time 1393113088 1 175 177 177 1003 2005 8.8
   1742054300.0026 Rx ;63# usb 1392.814 14 0 7505 136243 7505 0 660
   1742054300.0027 Rx ;74livn 0 0 0 0 0 0 0 0 1
   1742054300.0027 Rx ;98lis 0 1 1 0 1 1 0.85 0.79
   1742054300.0028 Rx ;57ird 0.700 0.361 3554 5573 1
   1742054300.0028 Rx ;51gyro0 4.3335 -0.0610352 1.15967 0
   1742054300.0029 Rx ;05hbt 1392.8149 122 1033 19.15 4 8 8.8 0.30 0
   1742054300.0029 Rx ;03time 1393115093 1 175 177 177 1003 2005 8.8
   1742054300.0030 Rx ;64# usb 1392.815 14 0 7505 136243 7505 0 660
   1742054300.0041 Rx ;74livn 0 0 0 0 0 0 0 0 1
   1742054300.0042 Rx ;98lis 0 1 1 0 1 1 0.85 0.79
   1742054300.0042 Rx ;58ird 0.700 0.362 3556 5562 1
   1742054300.0043 Rx ;81gyro0 -0.213411 -0.0438232 -0.164642 1
   1742054300.0043 Rx ;97hbt 1392.8160 122 1033 19.15 4 8 8.8 0.30 0
   1742054300.0044 Rx ;03time 1393115093 1 175 177 177 1003 2005 8.8
   1742054300.0044 Rx ;65# usb 1392.816 14 0 7505 136243 7505 0 660
   1742054300.0046 Rx ;74livn 0 0 0 0 0 0 0 0 1
   1742054300.0047 Rx ;98lis 0 1 1 0 1 1 0.85 0.79
   1742054300.0047 Rx ;58ird 0.700 0.362 3556 5562 1
   1742054300.0047 Rx ;16gyro0 3.9978 -0.183105 1.28174 0
   1742054300.0048 Rx ;91hbt 1392.8170 122 1033 19.15 4 8 9.0 0.30 0
   1742054300.0049 Rx ;96time 1393117079 1 175 177 178 984 1986 8.9
   1742054300.0049 Rx ;66# usb 1392.817 14 0 7505 136243 7505 0 660
   1742054300.0061 Rx ;74livn 0 0 0 0 0 0 0 0 1
   1742054300.0061 Rx ;98lis 0 1 1 0 1 1 0.85 0.79
   1742054300.0061 Rx ;79ird 0.699 0.362 3559 5554 1
   1742054300.0062 Rx ;39gyro0 -0.060823 -0.0743408 0.171051 1
   1742054300.0062 Rx ;92hbt 1392.8180 122 1033 19.15 4 8 9.0 0.30 0
   1742054300.0063 Rx ;96time 1393117079 1 175 177 178 984 1986 8.9
   1742054300.0064 Rx ;67# usb 1392.818 14 0 7505 136243 7505 0 660
   1742054300.0065 Rx ;74livn 0 0 0 0 0 0 0 0 1
   1742054300.0065 Rx ;98lis 0 1 1 0 1 1 0.85 0.79
   1742054300.0066 Rx ;79ird 0.699 0.362 3559 5554 1
   1742054300.0066 Rx ;03gyro0 4.15039 -0.213623 0.946045 0
   1742054300.0066 Rx ;02hbt 1392.8190 122 1033 19.15 4 8 8.9 0.30 0
   1742054300.0067 Rx ;73time 1393119080 1 175 177 178 998 2001 8.8
   1742054300.0068 Rx ;68# usb 1392.819 14 0 7505 136243 7505 0 660