Robobot SVN version 1179
From Rsewiki
Back to Robobot
Update note
What to do
- Changes to the "mqtt-client" are detailed to allow for a selective merge with your version.
Updated original version is available in SVN repository.
- For other changes, follow the hhh
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
...
ip_disp
- listening to pin 13 only
- turning on LED 16 as red when start is pressed