IEEERobotics / high-level

CV, localization, mapping, planning, and generally anything that will run on the PandaBoard
BSD 2-Clause "Simplified" License
2 stars 1 forks source link

Need to terminate serial interface threads #17

Closed dfarrell07 closed 11 years ago

dfarrell07 commented 11 years ago

During my unit tests, I create a comm.SerialInterface object and start it. When my tests complete, I need its threads to terminate, so that my tests will actually return. @napratin's latest updates seem to have changed SIs behavior in such a way that keeps it from terminating at the end of my tests (nothing bad implied, updates are good, lol).

I see that there's a quit command that I should be using to terminate the send and receive threads. So, I guess this boils down to a more general question about how I should send a command to SI, specifically a quit command. How do I do that, @napratin? Thanks!

napratin commented 11 years ago

@dfarrell07 Yes, the way SI works has changed a little, in order to properly do multiprocessing (it also doesn't break anymore if port is unavailable, so testing is easy). It's easiest for me to do this in code, so I am going to modify controller.py now and do it there. I haven't seen any updates to controller.py in the last few days, so I'm hoping no conflicts arise. Either way, my changes will be minimal, and git is there for managing conflicts.

Essentially, in controller.py (I've discussed this with Srinath):

  1. Create a SerialInterface Process instance and start it:
si = comm.SerialInterface()
si.start()
  1. Create a SerialCommand wrapper object, one for each client that needs to send/recv serial messages, and pass that in instead of the si object directly:
scPlanner = SerialCommand(si.commands, si.responses)  # si.commands and si.responses are process-safe shared structures
pPlanner = Process(target=planner.run, args=(bot_loc, blocks, zones, waypoints, scPlanner, bot_state, qMove_nav))

scNav = SerialCommand(si.commands, si.responses)
pNav = Process(target=nav.run, args=(bot_loc, course_map, waypoints, qNav_loc, scNav, bot_state, qMove_nav))
pNav.start()
  1. When done, call the quit() method on any one of the SerialCommand objects and the si process should terminate (it's harmless to have it running, though, and you might want to join on it at the very end):
scPlanner.quit()

While I'm in controller.py, as discussed with Srinath, I'm also going to add a shared blobs list that we need between vision and planner.

napratin commented 11 years ago

I've committed my changes to controller. I also modified vision to accept the changed set of arguments. Other processes also need to change their run method to accept all shared variables properly.

Note that SerialCommand exposes the same high-level methods that SerialInterface did earlier, so they may not need to modify anything on that front.