Skip to content

Commit f7651d7

Browse files
authored
Merge pull request #7 from mklomp/linetrace_fix
Fixing linetrace issues
2 parents c397ae6 + 4932c32 commit f7651d7

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

mirte_robot/linetrace.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@
1616
# Global shared memory objects (TODO: check if we need shared memory, why is server working?)
1717
stepper = multiprocessing.Value('b', True)
1818
do_step = multiprocessing.Value('b', False)
19-
is_running = False
19+
running = multiprocessing.Value('b', False)
2020

21-
def stop_mirte():
22-
global is_running
23-
process.terminate()
24-
is_running = False
21+
# the stop be stopped when:
22+
# 1) the code finishes
23+
# 2) the user stopped the process
24+
# 3) the websocket connection is closed
25+
def stop_mirte(terminate = True):
26+
global running
27+
if terminate:
28+
process.terminate()
29+
running.value = False
2530

26-
def load_mirte_module(stepper, do_step):
31+
def load_mirte_module(stepper, do_step, running):
2732

2833
def trace_lines(frame, event, arg):
2934
global do_step
@@ -46,7 +51,7 @@ def traceit(frame, event, arg):
4651
# Send the PID to the web interface and give it some time to call strace on this process
4752
# to see the output of this script
4853
server.send_message_to_all("pid:" + str(os.getpid()))
49-
time.sleep(0.1)
54+
time.sleep(0.2) #TODO: let client send signal when strace is started
5055

5156
sys.settrace(traceit)
5257
# rospy.init_node() for some reason needs to be called from __main__ when importing in the regular way.
@@ -64,6 +69,8 @@ def traceit(frame, event, arg):
6469
# Sending the linetrace 0 to the client
6570
server.send_message_to_all("0")
6671

72+
stop_mirte(False)
73+
6774
process = multiprocessing.Process(target = load_mirte_module, args=(stepper, do_step))
6875

6976
def start_mirte():
@@ -72,22 +79,22 @@ def start_mirte():
7279
# but, just in case make sure to stop this
7380
if process.is_alive():
7481
process.terminate()
75-
process = multiprocessing.Process(target = load_mirte_module, args=(stepper, do_step))
82+
process = multiprocessing.Process(target = load_mirte_module, args=(stepper, do_step, running))
7683
process.start()
7784

7885
def client_left(client, server):
7986
stop_mirte()
8087

8188
def message_received(client, server, message):
82-
global stepper, do_step, is_running
89+
global stepper, do_step, running
8390

8491
if message == "b": #break (pause)
8592
stepper.value = True
8693
if message == "c": #continue (play)
8794
stepper.value = False
88-
if not is_running:
95+
if not running.value:
8996
start_mirte()
90-
is_running = True
97+
running.value = True
9198
if message == "s": #step (step)
9299
do_step.value = True
93100
if message == "e": #exit (stop)

0 commit comments

Comments
 (0)