PYTHON AAAAAAAAAAAAAAAA
This commit is contained in:
@@ -18,11 +18,11 @@ class Noeud {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addCheminPossible(chemin){
|
addCheminPossible(chemin){
|
||||||
this.chemins.push(chemin)
|
this.chemins.push(chemin);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCheminsPossibles(){
|
getCheminsPossibles(){
|
||||||
return this.chemins
|
return this.chemins;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
import aiohttp
|
||||||
|
from aiohttp import web, WSCloseCode
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
async def http_handler(request):
|
||||||
|
payload = await request.text()
|
||||||
|
print(payload)
|
||||||
|
|
||||||
|
url = 'http://192.168.185.166/turtle/send'
|
||||||
|
headers = {'content-type': 'application/json'}
|
||||||
|
r = requests.post(url, data=payload, headers=headers)
|
||||||
|
|
||||||
|
print(r.text)
|
||||||
|
|
||||||
|
return web.Response(text=r.text)
|
||||||
|
|
||||||
|
|
||||||
|
def create_runner():
|
||||||
|
app = web.Application()
|
||||||
|
app.add_routes([
|
||||||
|
web.post('/', http_handler),
|
||||||
|
])
|
||||||
|
return web.AppRunner(app)
|
||||||
|
|
||||||
|
|
||||||
|
async def start_server(host="127.0.0.1", port=4444):
|
||||||
|
runner = create_runner()
|
||||||
|
await runner.setup()
|
||||||
|
site = web.TCPSite(runner, host, port)
|
||||||
|
await site.start()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
loop.run_until_complete(start_server())
|
||||||
|
loop.run_forever()
|
||||||
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
const URL = "192.168.185.166";
|
const ROBOT_URL = "192.168.185.166";
|
||||||
|
const CURL_URL = "localhost:4444";
|
||||||
const INFO_POSITION = 0x01;
|
const INFO_POSITION = 0x01;
|
||||||
const INFO_LED = 0x02;
|
const INFO_LED = 0x02;
|
||||||
|
|
||||||
@@ -10,14 +11,15 @@ let moteur = undefined;
|
|||||||
let led = undefined;
|
let led = undefined;
|
||||||
let position = undefined;
|
let position = undefined;
|
||||||
let pid = undefined;
|
let pid = undefined;
|
||||||
|
let turtle = undefined;
|
||||||
|
|
||||||
|
|
||||||
const connectSockets = () => {
|
const connectSockets = () => {
|
||||||
if ((socketMoteur != undefined) || (socketInfos != undefined)) {
|
if ((socketMoteur != undefined) || (socketInfos != undefined)) {
|
||||||
disconnectSocket();
|
disconnectSocket();
|
||||||
}
|
}
|
||||||
socketMoteur = new WebSocket("ws://" + URL + "/motors.ws");
|
socketMoteur = new WebSocket("ws://" + ROBOT_URL + "/motors.ws");
|
||||||
socketInfos = new WebSocket("ws://" + URL + "/infos.ws");
|
socketInfos = new WebSocket("ws://" + ROBOT_URL + "/infos.ws");
|
||||||
socketInfos.binaryType = "arraybuffer";
|
socketInfos.binaryType = "arraybuffer";
|
||||||
|
|
||||||
socketMoteur.onclose = function(event) {
|
socketMoteur.onclose = function(event) {
|
||||||
@@ -36,6 +38,9 @@ const connectSockets = () => {
|
|||||||
console.log("[socketInfos] Connection established");
|
console.log("[socketInfos] Connection established");
|
||||||
position.reset();
|
position.reset();
|
||||||
led.green();
|
led.green();
|
||||||
|
new Promise(r => setTimeout(r, 2000)).then(() => {
|
||||||
|
led.off();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
socketInfos.onclose = function(event) {
|
socketInfos.onclose = function(event) {
|
||||||
@@ -180,7 +185,7 @@ class Led {
|
|||||||
http = undefined;
|
http = undefined;
|
||||||
|
|
||||||
async send(color){
|
async send(color){
|
||||||
await fetch('http://' + URL + '/led/set_color', {
|
await fetch('http://' + ROBOT_URL + '/led/set_color', {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
||||||
mode: "no-cors",
|
mode: "no-cors",
|
||||||
@@ -236,7 +241,7 @@ class Position {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async reset() {
|
async reset() {
|
||||||
await fetch("http://" + URL + "/position/reset", {
|
await fetch("http://" + ROBOT_URL + "/position/reset", {
|
||||||
method: 'get',
|
method: 'get',
|
||||||
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
||||||
mode: "no-cors"
|
mode: "no-cors"
|
||||||
@@ -244,17 +249,49 @@ class Position {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Turtle {
|
||||||
|
|
||||||
|
async avancer(distance) {
|
||||||
|
const data = {
|
||||||
|
'type': 'dist',
|
||||||
|
'dist': distance,
|
||||||
|
}
|
||||||
|
await fetch("http://" + CURL_URL, {
|
||||||
|
method: "POST",
|
||||||
|
mode: "no-cors",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async tourner(angle) {
|
||||||
|
const data = {
|
||||||
|
'type': 'angle',
|
||||||
|
'angle': angle,
|
||||||
|
}
|
||||||
|
await fetch("http://" + CURL_URL, {
|
||||||
|
method: "POST",
|
||||||
|
mode: "no-cors",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
|
|
||||||
|
|
||||||
connectSockets();
|
connectSockets();
|
||||||
moteur = new Moteur();
|
moteur = new Moteur();
|
||||||
led = new Led();
|
led = new Led();
|
||||||
position = new Position(socketInfos);
|
position = new Position(socketInfos);
|
||||||
pid = new PID();
|
pid = new PID();
|
||||||
|
turtle = new Turtle();
|
||||||
led.red();
|
led.red();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
|
||||||
@@ -286,3 +323,16 @@ async function run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function test() {
|
||||||
|
let d = 190;
|
||||||
|
const data = {
|
||||||
|
'type': 'dist',
|
||||||
|
'dist': d,
|
||||||
|
}
|
||||||
|
await fetch("http://127.0.0.1:4444/", {
|
||||||
|
method: "POST",
|
||||||
|
mode: "no-cors",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user