Robobot SVN version 1179: Difference between revisions

From Rsewiki
Line 2: Line 2:


== Update note ==
== Update note ==
* 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 shutdown.
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 ===
=== What to do ===


* Changes to the "mqtt-client" are detailed to allow for a selective merge with your version.
* Changes to the "mqtt-client" are detailed to allow for a selective merge with your version.
  Updated original version is available in SVN repository.
 
====mqtt-client====
====mqtt-client====
  cd ~/svn/robobot/mqtt_python
  cd ~/svn/robobot/mqtt_python
Line 18: Line 23:
====ip_disp====
====ip_disp====
  cd ~svn/robobot/ip_disp/build
  cd ~svn/robobot/ip_disp/build
svn up ..
make -j3
====teensy_interface====
cd ~svn/robobot/teensy_interface/build
  svn up ..
  svn up ..
  make -j3
  make -j3

Revision as of 19:28, 15 March 2025

Back to Robobot

Update note

  • 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 shutdown.

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 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

teensy_firmware_8