Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
Test du code de detection a la cam
Browse files Browse the repository at this point in the history
  • Loading branch information
LeProblemeEDMN committed Oct 3, 2024
1 parent 151723b commit 8534da6
Show file tree
Hide file tree
Showing 27 changed files with 372 additions and 272 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/team2024.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions raspberrypi/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions raspberrypi/.idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions raspberrypi/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions raspberrypi/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions raspberrypi/.idea/raspberrypi.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions raspberrypi/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added raspberrypi/cameraMatrix.npy
Binary file not shown.
2 changes: 1 addition & 1 deletion raspberrypi/daughter_cards/wheeledbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def goto_stop(self, x, y,sensors, theta=None, direction=None, finalangle=None, l

#print(trigo,ang,theta)
#print(" ",xmin,xmax,ymin,ymax)
if(xmin<0 or xmax>2000 or ymin<0 or ymax>3000):
if(xmin<0 or xmax>3000 or ymin<0 or ymax>2000):
trigo =not trigo

#print(trigo,['clock','trig'][trigo])
Expand Down
Binary file added raspberrypi/distCoeffs.npy
Binary file not shown.
5 changes: 5 additions & 0 deletions raspberrypi/managers/buttons_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ def putrobot(self):
def ready_stage(self):
self.logger.sendLogStatus("Robot" ,colorise("Robot Ready !", Colors.RED, Colors.BOLD))
print("ready")
self.red.off()
self.green.off()
self.blue.off()
self.orange.off()
self.green.set_function(None)
self.tirette.set_function(
Thread(target=self.run_match, daemon=True).start)
#self.tirette.set_active_high(True)
Expand Down
106 changes: 106 additions & 0 deletions raspberrypi/managers/simple_wifi.py
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!")



2 changes: 1 addition & 1 deletion raspberrypi/robots/team2024/PanneauxSolaires.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def procedure(self):
#depart = np.flip(np.array(self.robot.geo.get('BaseJ1INIT')) + np.array([0,0]))
fin = np.flip(np.array(self.robot.geo.get('PSJauneFin')) + np.array([self.radiusAile,140]))


#self.wb.goto_stop(depart[0],depart[1],self.robot.sensors,theta=ang_approche)
if(not self.yellow):
self.barriere.aile_d_ferme()
Expand Down
45 changes: 14 additions & 31 deletions raspberrypi/t.py
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])
44 changes: 28 additions & 16 deletions raspberrypi/test.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
import cv2, glob
import math
from tracking.libs.positionDetectorMultiple import PositionDetectorMultiple
print("a")
cam = cv2.VideoCapture(1)
import numpy as np

if not cam.isOpened():
print("Cannot open camera")
exit()
A=np.array([[ 1.00000000e+00, 0.00000000e+00 , 0.00000000e+00 , 0.00000000e+00],
[ 0.00000000e+00 , 8.45727822e-01 , 5.33614516e-01, 4.10883177e+02],
[ 0.00000000e+00, 5.33614516e-01 , -8.45727822e-01 ,-6.51210423e+02],
[ 0.00000000e+00 , 0.00000000e+00 , 0.00000000e+00, 1.00000000e+00]])
pos=np.array([0,0,1220,1])
#[-1.59377493e-01][ 5.09197442e+01][ 1.54207681e+03]
print(np.matmul(A,pos))
#print(np.linalg.inv(A))
print(np.matmul(np.linalg.inv(A),np.array([0,1.51207681e+03,0,1])))
#import cv2, glob
#
#from tracking.libs.positionDetectorMultiple import PositionDetectorMultiple
#print("a")
#cam = cv2.VideoCapture(1)

#if not cam.isOpened():
# print("Cannot open camera")
# exit()

#pd=PositionDetectorMultiple()
#pd.KNOW_WIDTH_MARKER=65
#pd.KNOW_WIDTH_MARKER=600
#pd.init([560,1000,880],0,-math.pi/2)
print("read")
while True:
ret_val, img = cam.read()
#print(img.shape)
cv2.imshow('my webcam', img)
if cv2.waitKey(1) == 27:
break # esc to quit
cv2.destroyAllWindows()
#print("read")
#while True:
# ret_val, img = cam.read()
# #print(img.shape)
# cv2.imshow('my webcam', img)
# if cv2.waitKey(1) == 27:
# break # esc to quit
#cv2.destroyAllWindows()
"""
print(wb.left_codewheel_radius.get())
print(wb.right_wheel_radius.get())
Expand Down Expand Up @@ -47,7 +59,7 @@
#while True:
# True
#print(wb.get_position())
print("arrivé",wb.get_position())
#print("arrivé",wb.get_position())

#from managers.buttons_manager import ButtonsManager
#ButtonsManager(None).begin()
Expand Down
1 change: 1 addition & 0 deletions raspberrypi/tests/wbTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
wheeledbase.start_match()
wheeledbase.set_position(1000,1000,0)
wheeledbase.goto_stop(1000,1000, sensors,theta=-math.pi/2)

time.sleep(1)

#wheeledbase.goto_stop(1000,1000, sensors,theta=0)
Expand Down
Loading

0 comments on commit 8534da6

Please sign in to comment.