-
Notifications
You must be signed in to change notification settings - Fork 1
Main manager #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Main manager #23
Changes from 100 commits
603a4e7
772314b
dece7b4
923856a
9188d3a
895f19b
c2e72cb
caacc48
2a05b38
f536c1a
ed66194
3a9d1e3
d0116d1
7cdc0e2
12b0e4d
d0597c0
583775b
7bd7118
88a16ce
b16f35f
9556f2b
728d40d
27d9f4d
6ee55a0
3c03eec
5fff2b0
5257fc3
4ff0624
7c8225f
1762638
cdbcf48
79550b3
f4efd9e
ad7f2c0
4906d16
8a55a2b
746b2c6
96faa64
599ba8e
ffed0fe
a594278
9bfa002
06b8ff1
2fc2883
e71c658
f73035f
b120946
f6928f9
e04f42a
5cdb8be
45045be
2d08d23
c4f8de6
b5df107
4b16f50
0109b51
0a76891
01df9b4
2fb2063
89c90ab
459274b
c46ad65
20b95a2
899618c
48117f7
967d232
e4e0d31
8a00574
77a7eba
ebb85a9
8606da1
459e5e0
5b6d3ff
0a7e74f
4a0d602
0e2a082
298e430
dc5b418
073cdae
574293e
aac925b
0ce59a1
89666e8
2126db6
68c134b
1d1218b
f335843
c3212b6
c1e92e5
863741d
f76afa7
61a34f2
e4b21ec
b7af974
0d15e34
d1d32ea
0525d89
8a7aeae
1efb726
d61c722
752b677
168f5bd
8eaf919
73d7321
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C'est quoi la logique derriere avoir celui la dans sont propre dossier? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,133 +1,156 @@ | ||
| from pyPS4Controller.controller import Controller | ||
| import time | ||
| import os | ||
| from threading import Thread | ||
|
|
||
| #Pour le protocole I2C de communication entre la rasberie Pi et l'arduino | ||
| import smbus #type: ignore #ignore the module could not be resolved error because it is a linux only module | ||
| import numpy as np | ||
| import struct | ||
|
|
||
| from src.HL.programme.programme import Program | ||
| from src.HL.Autotech_constant import MAX_ANGLE | ||
| ################################################### | ||
| #Intialisation du protocole I2C | ||
| #Intialisation du protocole zmq | ||
| ################################################## | ||
|
|
||
| # Create an SMBus instance | ||
| bus = smbus.SMBus(1) # 1 indicates /dev/i2c-1 | ||
|
|
||
| # I2C address of the slave | ||
| SLAVE_ADDRESS = 0x08 | ||
|
|
||
| def write_vitesse_direction(vitesse,direction): | ||
| # Convert string to list of ASCII values | ||
| data = struct.pack('<ff', float(vitesse), float(direction)) | ||
| bus.write_i2c_block_data(SLAVE_ADDRESS, 0, list(data)) | ||
| def envoie_donnee(Voiture): #si utilisation de la voiture directement | ||
| print("lancement de l'i2c") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use logging |
||
| import smbus | ||
| import struct | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moyen fan des import ici mais ca ce defend |
||
| from src.HL.Autotech_constant import SLAVE_ADDRESS | ||
|
|
||
| ################################################### | ||
| #Intialisation des moteurs | ||
| ################################################## | ||
| bus = smbus.SMBus(1) | ||
| while True: | ||
| try : | ||
| data = struct.pack('<ff', float(round(Voiture.vitesse_mms)), float(round(Voiture.direction_d))) | ||
| bus.write_i2c_block_data(SLAVE_ADDRESS, 0, list(data)) | ||
| #time.sleep(0.00005) | ||
| except Exception as e: | ||
| print("i2c mort" + str(e)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use logging |
||
| time.sleep(1) | ||
|
|
||
| direction_d = 0 # angle initiale des roues en degrés | ||
| vitesse_m = 0 # vitesse initiale en métre par milliseconde | ||
|
|
||
| #paramètres de la fonction vitesse_m_s, à étalonner | ||
| vitesse_max_m_s_hard = 8 #vitesse que peut atteindre la voiture en métre | ||
| vitesse_max_m_s_soft = 2 #vitesse maximale que l'on souhaite atteindre en métre par seconde | ||
| vitesse_min_m_s_soft = -2 #vitesse arriere que l'on souhaite atteindre en métre | ||
|
|
||
| angle_degre_max = +18 #vers la gauche | ||
|
|
||
|
|
||
| MAX_LEFT = -32767 + 3000 # deadzone 3000 | ||
|
|
||
| # fonction naturel map de arduino pour plus de lisibilité | ||
| def map_range(x, in_min,in_max, out_min, out_max): | ||
| return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min | ||
|
|
||
|
|
||
| class PS4ControllerProgram(Program): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. t'utilise jamais cette class si? |
||
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
| self.name = "PS4 Controller" | ||
| self.running = False | ||
| self.controls_car = True | ||
|
|
||
| #initialisation | ||
| self.controller = MyController(interface="/dev/input/js0", connecting_using_ds4drv=False) | ||
| self.controller.stop = True | ||
|
|
||
| def set_direction_degre(angle_degre) : | ||
| global direction_d | ||
| direction_d = angle_degre | ||
| print("angle_degré: ",direction_d,"vitesse: ",vitesse_m) | ||
|
|
||
| def set_vitesse_m_ms(vitesse_m_ms): | ||
| global vitesse_m | ||
| vitesse_m = vitesse_m_ms | ||
| print("angle_degré: ",direction_d,"vitesse: ",vitesse_m) | ||
|
|
||
| def recule(): #actuellement ne sert a rien car on peux juste envoyer une vitesse négative | ||
| global vitesse_m | ||
| vitesse_m = -2000 | ||
|
|
||
| def start(self): | ||
| self.running = True | ||
| self.controller.stop = False | ||
| self.thread = Thread( | ||
| target=self.controller.listen, kwargs=dict(timeout=60), | ||
| daemon=True | ||
| ) | ||
| self.thread.start() | ||
|
|
||
| def kill(self): | ||
| self.controller.stop = True | ||
| self.running = False | ||
|
|
||
| @property | ||
| def vitesse_d(self): | ||
| return self.controller.vitesse_mms | ||
|
|
||
| @property | ||
| def direction_d(self): | ||
| return self.controller.direction_d | ||
|
|
||
| class MyController(Controller): | ||
|
|
||
| def __init__(self, **kwargs): | ||
| Controller.__init__(self, **kwargs) | ||
| super().__init__(**kwargs) | ||
| self.vitesse_mms = 0 # vitesse initiale en métre par milliseconde | ||
| self.direction_d = 0 # angle initiale des roues en degrés | ||
| self.filtered = 0 | ||
| self.alpha = 0.3 | ||
| self.running = 0 | ||
|
|
||
| def stable_direction(self,value): | ||
|
|
||
| # Deadzone | ||
| if value < MAX_LEFT: | ||
| target = -MAX_ANGLE | ||
| else: | ||
| target = map_range(value, -32767, 0, -MAX_ANGLE, 0) | ||
|
|
||
| # Low-pass filtering | ||
| self.filtered = self.filtered * (1 - self.alpha) + target * self.alpha | ||
| return self.filtered | ||
|
|
||
|
|
||
| def on_R2_press(self,value): | ||
| vit = map_range(value,-32252,32767,0,vitesse_max_m_s_soft*1000) | ||
| if (vit < 0): | ||
| set_vitesse_m_ms(0) | ||
| self.vitesse_mms = 0 | ||
| else: | ||
| set_vitesse_m_ms(vit) | ||
| self.vitesse_mms = vit | ||
| def on_R2_release(self): # arrete la voiture lorsque L2 est arrété d'étre préssé. | ||
| set_vitesse_m_ms(0) | ||
| self.vitesse_mms = 0 | ||
|
|
||
|
|
||
|
|
||
| def on_L3_x_at_rest(self): | ||
| set_direction_degre(0) | ||
| self.direction = 0 | ||
|
|
||
| def on_R1_press(self): #arret d'urgence | ||
| set_vitesse_m_ms(0) | ||
| self.vitesse_mms = 0 | ||
|
|
||
| def on_R1_release(self): | ||
| set_vitesse_m_ms(0) | ||
| self.vitesse_mms = 0 | ||
|
|
||
| def on_L3_up(self,value): | ||
| pass | ||
| def on_L3_down(self,value): | ||
| pass | ||
|
|
||
|
|
||
| def on_L3_right(self,value): | ||
| # print("x_r :", value, "degré : ",map_range(value,-32767, 32767, 60, 120)) | ||
| dir = map_range(value, 0, 32767, 0, angle_degre_max) | ||
| set_direction_degre(dir) | ||
| dir = map_range(value, 0, 32767, 0, MAX_ANGLE) | ||
| self.direction_d = dir | ||
|
|
||
| def on_L3_left(self,value): | ||
| print("x_r :", value, "degré : ",map_range(value,-32767, 0, -angle_degre_max, 0 )) | ||
| dir = map_range(value,-32767, 0, -angle_degre_max, 0 ) | ||
| set_direction_degre(dir) | ||
| #print("x_r :", value, "degré : ",map_range(value,-32767, 0, -MAX_ANGLE, 0 )) | ||
| dir = self.stable_direction(value) | ||
| self.direction_d = dir | ||
|
|
||
|
|
||
| def on_L2_press(self, value): | ||
| print("x_r :", value, "degré : ",map_range(value,-32767, 32767, 60, 120)) | ||
| #print("x_r :", value, "degré : ",map_range(value,-32767, 32767, 60, 120)) | ||
| vit = map_range(value,-32252,32767,0,vitesse_min_m_s_soft*1000) | ||
| if (vit > 0): | ||
| set_vitesse_m_ms(0) | ||
| self.vitesse_mms = 0 | ||
| else: | ||
| set_vitesse_m_ms(vit) | ||
| self.vitesse_mms = vit | ||
|
|
||
| def on_L2_release(self): #arrete la voiture lorsque L2 est arrété d'étre préssé. | ||
| set_vitesse_m_ms(0) | ||
|
|
||
| #envoie de la direction et de l'angle toute les millisecondes | ||
| def envoie_direction_degre(): | ||
| while True : | ||
| write_vitesse_direction(int(vitesse_m), int(direction_d)) | ||
| time.sleep(0.001) | ||
|
|
||
|
|
||
| # boucle principal | ||
| controller = MyController(interface="/dev/input/js0", connecting_using_ds4drv=False) | ||
| try: | ||
| Thread(target = envoie_direction_degre, daemon=True).start() | ||
| controller.listen(timeout=60) | ||
|
|
||
| except KeyboardInterrupt: | ||
| print("Arrêt du programme") | ||
| controller.stop() | ||
| exit(0) | ||
| self.vitesse_mms = 0 | ||
|
|
||
| def on_L3_up(self,value): | ||
| pass | ||
| def on_L3_down(self,value): | ||
| pass | ||
| def on_L3_y_at_rest(self): | ||
| pass | ||
|
|
||
| if __name__ == "__main__": | ||
| controller = MyController(interface="/dev/input/js0", connecting_using_ds4drv=False) | ||
| try: | ||
| Thread(target = envoie_donnee,args=(controller,), daemon=True).start() | ||
| controller.listen(timeout=60) | ||
|
|
||
| except KeyboardInterrupt: | ||
| print("Arrêt du programme") | ||
| controller.stop() | ||
| exit(0) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import io | ||
| import logging | ||
| import socketserver | ||
| from http import server | ||
| from threading import Condition | ||
|
|
||
| from picamera2 import Picamera2 | ||
| from picamera2.encoders import JpegEncoder | ||
| from picamera2.outputs import FileOutput | ||
|
|
||
| # HTML page for the MJPEG streaming demo | ||
| PAGE = """\ | ||
| <html> | ||
| <head> | ||
| <title>RaspberryTips Pi Cam Stream</title> | ||
| </head> | ||
| <body> | ||
| <h1>Raspberry Tips Pi Camera Live Stream Demo</h1> | ||
| <img src="stream.mjpg" width="640" height="480" /> | ||
| </body> | ||
| </html> | ||
| """ | ||
|
|
||
| # Class to handle streaming output | ||
| class StreamingOutput(io.BufferedIOBase): | ||
| def __init__(self): | ||
| self.frame = None | ||
| self.condition = Condition() | ||
|
|
||
| def write(self, buf): | ||
| with self.condition: | ||
| self.frame = buf | ||
| self.condition.notify_all() | ||
|
|
||
| # Class to handle HTTP requests | ||
| class StreamingHandler(server.BaseHTTPRequestHandler): | ||
| def do_GET(self): | ||
| if self.path == '/': | ||
| # Redirect root path to index.html | ||
| self.send_response(301) | ||
| self.send_header('Location', '/index.html') | ||
| self.end_headers() | ||
| elif self.path == '/index.html': | ||
| # Serve the HTML page | ||
| content = PAGE.encode('utf-8') | ||
| self.send_response(200) | ||
| self.send_header('Content-Type', 'text/html') | ||
| self.send_header('Content-Length', len(content)) | ||
| self.end_headers() | ||
| self.wfile.write(content) | ||
| elif self.path == '/stream.mjpg': | ||
| # Set up MJPEG streaming | ||
| self.send_response(200) | ||
| self.send_header('Age', 0) | ||
| self.send_header('Cache-Control', 'no-cache, private') | ||
| self.send_header('Pragma', 'no-cache') | ||
| self.send_header('Content-Type', 'multipart/x-mixed-replace; boundary=FRAME') | ||
| self.end_headers() | ||
| try: | ||
| while True: | ||
| with output.condition: | ||
| output.condition.wait() | ||
| frame = output.frame | ||
| self.wfile.write(b'--FRAME\r\n') | ||
| self.send_header('Content-Type', 'image/jpeg') | ||
| self.send_header('Content-Length', len(frame)) | ||
| self.end_headers() | ||
| self.wfile.write(frame) | ||
| self.wfile.write(b'\r\n') | ||
| except Exception as e: | ||
| logging.warning( | ||
| 'Removed streaming client %s: %s', | ||
| self.client_address, str(e)) | ||
| else: | ||
| # Handle 404 Not Found | ||
| self.send_error(404) | ||
| self.end_headers() | ||
|
|
||
| # Class to handle streaming server | ||
| class StreamingServer(socketserver.ThreadingMixIn, server.HTTPServer): | ||
| allow_reuse_address = True | ||
| daemon_threads = True | ||
|
|
||
| # Create Picamera2 instance and configure it | ||
| picam2 = Picamera2() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use a if name = main block |
||
| picam2.configure(picam2.create_video_configuration(main={"size": (640, 480)})) | ||
| output = StreamingOutput() | ||
| picam2.start_recording(JpegEncoder(), FileOutput(output)) | ||
|
|
||
| try: | ||
| # Set up and start the streaming server | ||
| address = ('', 8000) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C'est quoi ''? une ip? si oui utilise localhost ou 0.0.0.0 |
||
| server = StreamingServer(address, StreamingHandler) | ||
| server.serve_forever() | ||
| finally: | ||
| # Stop recording when the script is interrupted | ||
| picam2.stop_recording() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pourquoi preciser une partie et pas tout? Pas sure qu'on precis ici car il faudrais le tenir a jour en plus du pyproject.tml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
je voulais préciser car se sont des dépendance qu'il faut installer pas sur uv. le reste est dans le uv sync --rpi