0

I'm working on controlling robot with commands send from android app through HTTPRequestHandler on Raspberry Pi.

class RequestHandler_httpd(BaseHTTPRequestHandler):   
  def do_GET(self):
    global Request
    messagetosend = bytes('x',"utf")
    self.send_response(200)
    self.send_header('Content-Type', 'text/plain')
    self.send_header('Content-Length', len(messagetosend))
    self.end_headers()
    self.wfile.write(messagetosend)
    Request = self.requestline
    Request = Request[5 : int(len(Request)-9)]
    print(Request)
    global hight, speed, sleep
    while Request == 'forward':
        Forward()
    while Request == 'turnleft':
        TurnLeft()
    while Request == 'turnright':
        TurnRight()
    while Request == 'base':
        BasePosition()
    return

My problem is that when I send command from my phone which is basically ip:port/x robot gets stuck on one function. If I for example want to use function "Forward" it will keep doing forward even when next request will be "turnleft". It works if I just use if statements but I want my robot to constantly execute function until I want to use different function. There's no loop in the functions Forward, TurnLeft, TurnRight, BasePosition.

Neidd
  • 61
  • 6
  • My problem with that is if I create while loop with few if's that checks value of Request it still works the same way. It ignores requests after frist one. I guess it's because program doesn't really "listen" for next requests while it's stuck in the while loop, if that's the case then any idea how to fix that? – Neidd Jul 26 '20 at 17:51
  • Maybe you should use `if` instead of all the `while` loops. If you want to have a loop that sends many GET requests I think you should try a single `while` loop (with all the `if` statements inside it). – Daniser Jul 26 '20 at 20:02

0 Answers0