You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My end goal is to create an interface that can control a Crazyflie drone with a few buttons.
I have a flask application for that, here is app.py:
from flask import Flask, render_template
from flask_sock import Sock
from pycrazyswarm import Crazyswarm
swarm = Crazyswarm()
cf = swarm.allcfs.crazyflies[0]
app = Flask(__name__)
sock = Sock(app)
@app.route('/')
def index():
return render_template('index.html')
@sock.route('/action')
def echo(sock):
while True:
data = sock.receive()
if data == 'left':
print("LEFT")
cf.goTo([-1.,0,0],0.,0.,True,1.)
if data == 'right':
cf.goTo([1.,0,0],0.,0.,True,1.)
if data == 'forward':
cf.goTo([0.,1.,0],0.,0.,True,1.)
if data == 'back':
cf.goTo([0.,-1.,0],0.,0.,True,1.)
if data =='take off':
print('take off....')
cf.takeoff(targetHeight=1.0,duration=2.5)
if data =='land':
print('...landing, please wait')
cf.land(targetHeight=1.0,duration=2.5)
if __name__ == '__main__':
app.run(debug=True)
and here is index.html
<!doctype html>
<html>
<head>
<title>Drone</title>
</head>
<script>
var socket = new WebSocket('ws://' + location.host + '/action');
function sendText(button) {
var text = button.value; // Get the value of the button
socket.send(text); // Send the text to the server
}
</script>
<body>
<h1>Drone Controller</h1>
<div id="log"></div>
<br>
<button value="left" onclick="sendText(this)">Left</button>
<button value="right" onclick="sendText(this)">Right</button>
<button value="back" onclick="sendText(this)">Back</button>
<button value="forward" onclick="sendText(this)">Forward</button>
<button value="take off" onclick="sendText(this)">Take off</button>
<button value="land" onclick="sendText(this)">Land</button>
</body>
</html>
I run the programs using python3 app.py and then access the interface through my browser at 0.0.0.0:5000
The issue is that I can use any of the buttons once, but then the program crashes and I get this error: shutdown request: [:/CrazyflieAPI] Reason: new node registered with same name
This line
cf = swarm.allcfs.crazyflies[0]
Gets only called once, and after that, each time a button was pressed, only the code block within the action-socket end point would be run. So I do not quite understand why I get that error. I am only using one Crazyflie-drone, which means that I have only one node. Right?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi!
My end goal is to create an interface that can control a Crazyflie drone with a few buttons.
I have a flask application for that, here is app.py:
and here is index.html
I run the programs using python3 app.py and then access the interface through my browser at 0.0.0.0:5000
The issue is that I can use any of the buttons once, but then the program crashes and I get this error:
shutdown request: [:/CrazyflieAPI] Reason: new node registered with same name
This line
cf = swarm.allcfs.crazyflies[0]
Gets only called once, and after that, each time a button was pressed, only the code block within the action-socket end point would be run. So I do not quite understand why I get that error. I am only using one Crazyflie-drone, which means that I have only one node. Right?
Beta Was this translation helpful? Give feedback.
All reactions