-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import pickle | ||
import time | ||
import socket | ||
import threading | ||
|
||
ERROR_OPCODE = 0x01 | ||
END_OPCODE = 0x00 | ||
class WiFiManager: | ||
""" | ||
This class implement a simple wifi manager. There is two components the client (typically the raspberry pi) and the | ||
server (typically the jetson nano). The client ask things to the server (the opposite is not possible). | ||
""" | ||
def __init__(self,ip_connect,port_connect,role): | ||
""" | ||
See the doc on the own cloud | ||
ip_connect: ip of the server (localhost if role=="server") | ||
port_connect: port of the server | ||
role: "server" or "client" | ||
""" | ||
self.server_ip = ip_connect | ||
self.server_port = port_connect | ||
self.role = role | ||
if(role == "server"): | ||
self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
self.functions_call=dict() | ||
self.functions_call[ERROR_OPCODE]=self.error | ||
self.functions_call[END_OPCODE] = self.close | ||
else: | ||
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
|
||
|
||
def start(self): | ||
""" | ||
Start the server or client and make the connections. | ||
""" | ||
if (self.role == "server"): | ||
self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
self.server_socket.bind((self.server_ip, self.server_port)) | ||
self.server_socket.listen(1) | ||
self.client_socket, client_address = self.server_socket.accept() | ||
#make a thread to receipt the instructions in parrallel | ||
self.thread = threading.Thread(target=self.server_job) | ||
self.alive=True | ||
self.thread.start() | ||
else: | ||
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
print("connect") | ||
self.client_socket.connect((self.server_ip, self.server_port)) | ||
|
||
if(self.role == "server"): | ||
self.alive=True | ||
|
||
|
||
def server_job(self): | ||
""" | ||
Server function | ||
""" | ||
while(self.alive): | ||
data=self.receive() | ||
if data is None: | ||
continue | ||
id_op=data[0] | ||
if not self.functions_call.keys().__contains__(id_op): | ||
print("Wifi communication: Error op code not valid.") | ||
else: | ||
result=self.functions_call[id_op](data[1:]) | ||
if(result!=None): | ||
self.send(result) | ||
|
||
|
||
def send(self, data): | ||
""" | ||
Send data | ||
""" | ||
serialized_data = pickle.dumps(data) | ||
self.client_socket.send(serialized_data) | ||
|
||
def send_return(self, data): | ||
""" | ||
Can only be used by the client to send an instruction and wait for the result. | ||
""" | ||
serialized_data = pickle.dumps(data) | ||
self.client_socket.send(serialized_data) | ||
return self.receive() | ||
|
||
def receive(self): | ||
serialized_data = self.client_socket.recv(4096) | ||
if len(serialized_data)==0: | ||
return None | ||
received_data = pickle.loads(serialized_data) | ||
return received_data | ||
|
||
|
||
def close(self,args): | ||
if (self.role == "server"): | ||
self.server_socket.close() | ||
self.alive = False | ||
self.client_socket.close() | ||
|
||
|
||
def error(self,args): | ||
print("Wifi communication: error raised by the user!") | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,20 @@ | ||
#import imp | ||
from daughter_cards.wheeledbase import WheeledBase, POSITIONCONTROL_LINVELKP_ID | ||
from daughter_cards.actionneur import Actionneur | ||
from common.serialtypes import FLOAT, STRING, INT | ||
from common.serialtalking import GETUUID_OPCODE, SerialTalking | ||
# import imp | ||
from managers.simple_wifi import WiFiManager | ||
import time | ||
import sys | ||
|
||
#Gestion du port série | ||
if 'linux' in sys.platform: | ||
serial_path = '/dev/ttyUSB0' | ||
else: | ||
serial_path = 'COM11' | ||
def square(args): | ||
return args[0] ** 2 | ||
|
||
ww = Actionneur(None, '/dev/ttyUSB0') | ||
|
||
aa = ww.AX12(254, ww) | ||
aa.reset() | ||
time.sleep(1) | ||
aa.move(0) | ||
def printing(args): | ||
print(args) | ||
|
||
#while 1: | ||
#ww.set_velocities(1,0) | ||
#print(ww.get_position()) | ||
|
||
#ww.turnonthespot(180) | ||
#ww.set_velocities(1,0) | ||
|
||
|
||
#LEFTCODEWHEEL_RADIUS_VALUE = 21.90460280828869 | ||
#RIGHTCODEWHEEL_RADIUS_VALUE = 22.017182927267537 | ||
#ODOMETRY_AXLETRACK_VALUE = 357.5722465739272 | ||
# verifier les moteurs sans assver (vrif les sens de marche) open loop velocities | ||
# verifier les codeuses et leur sens | ||
# Faire la metrologie et l'enregistrer | ||
# calibrer l'odométrie (verif la precision) | ||
# calib asservisseement | ||
communication = WiFiManager("10.0.0.11", 25565,"client") | ||
communication.start() | ||
print("printing",communication.send([4,"Coucou test"])) | ||
t=time.time() | ||
for i in range(100): | ||
print("square:",communication.send_return([3,i])) | ||
print(time.time()-t) | ||
communication.send([0x00]) |