diff --git a/avanceret/hovercraft/controller/main.py b/avanceret/hovercraft/controller/main.py index 2fd5106..a4ce1e1 100644 --- a/avanceret/hovercraft/controller/main.py +++ b/avanceret/hovercraft/controller/main.py @@ -11,11 +11,18 @@ import radio radio.config(group=99, power=7) radio.on() +throttle = 0 +flying = False + def move_forward(): - pass + throttle += 50 + if throttle > 100: + throttle = 100 def move_back(): - pass + throttle -= 50 + if throttle < 0: + throttle = 0 def turn_right(): pass @@ -23,13 +30,29 @@ def turn_right(): def turn_left(): pass +def take_of(): + #switch hover motor on + flying = True + pass + +def land(): + #switch hover motor off + flying = False + pass + while True: - command = radio.receive() - if command == "forward": - move_forward() - elif command == "back": - move_back() - elif command == "right": - turn_right() - elif command == "left": - turn_left() + Arm = radio.receiveValue("A") + if flying == True: + if command == "forward": + move_forward() + elif command == "back": + move_back() + elif command == "right": + turn_right() + elif command == "left": + turn_left() + elif command == "land": + land() + else: + if command == ("take_of"): + take_of() diff --git a/avanceret/hovercraft/remote/main.py b/avanceret/hovercraft/remote/main.py index ef6b278..d0303ba 100644 --- a/avanceret/hovercraft/remote/main.py +++ b/avanceret/hovercraft/remote/main.py @@ -11,12 +11,29 @@ import radio radio.config(group=99, power=7) radio.on() +flying = False + +def take_of(): + flying = True + radio.sendValue("takeof", flying) + +def land(): + flying = False + radio.sendValue("land", flying) + while True: - if accelerometer.was_gesture("down"): - radio.send("forward") - if accelerometer.was_gesture("up"): - radio.send("back") - if accelerometer.was_gesture("left"): - radio.send("left") - if accelerometer.was_gesture("right"): - radio,send("right") \ No newline at end of file + if flying == True: + if accelerometer.was_gesture("down"): + radio.send("forward") + if accelerometer.was_gesture("up"): + radio.send("back") + if accelerometer.was_gesture("left"): + radio.send("left") + if accelerometer.was_gesture("right"): + radio.send("right") + if button_a.was_pressed(): + if flying != True: + take_of() + if button_b.was_pressed(): + if flying != False: + land() \ No newline at end of file