Compare commits
7 Commits
898dd0a153
...
86cb6bfa72
| Author | SHA1 | Date | |
|---|---|---|---|
| 86cb6bfa72 | |||
| 1ce0e60593 | |||
| 99a434bd55 | |||
| 32926ced63 | |||
| c4417ba6ef | |||
| 3cb9cb3eed | |||
| 38b847bf24 |
7
.vscode/settings.json
vendored
7
.vscode/settings.json
vendored
@ -16,6 +16,11 @@
|
||||
"servomoteur.h": "c",
|
||||
"moteurs.h": "c",
|
||||
"messagerie_applicative.h": "c",
|
||||
"config_robot.h": "c"
|
||||
"config_robot.h": "c",
|
||||
"wifi.h": "c",
|
||||
"string.h": "c",
|
||||
"lwip_nosys.h": "c",
|
||||
"async_context.h": "c",
|
||||
"wifi_settings.h": "c"
|
||||
}
|
||||
}
|
||||
4
.vscode/tasks.json
vendored
4
.vscode/tasks.json
vendored
@ -2,7 +2,7 @@
|
||||
"tasks": [
|
||||
{
|
||||
"type": "shell",
|
||||
"command": "cd build; cmake ../; make",
|
||||
"command": "mkdir -p build; cd build; cmake ../ -DPICO_BOARD=pico_w; make",
|
||||
"label": "CMake in build/",
|
||||
"problemMatcher": [],
|
||||
"group": {
|
||||
@ -12,7 +12,7 @@
|
||||
},
|
||||
{
|
||||
"type": "shell",
|
||||
"command": "cd build; cmake ../; make Flash",
|
||||
"command": "cd build; cmake ../ -DPICO_BOARD=pico_w; make Flash",
|
||||
"label": "CMake & Make & Flash",
|
||||
"problemMatcher": [],
|
||||
"group": {
|
||||
|
||||
@ -39,12 +39,14 @@ add_executable(Mon_Projet
|
||||
VL53L8CX_ULD_API/src/vl53l8cx_plugin_motion_indicator.c
|
||||
VL53L8CX_ULD_API/src/vl53l8cx_plugin_xtalk.c
|
||||
VL53L8_2024.c
|
||||
Wifi.c
|
||||
Platform/platform.c
|
||||
)
|
||||
|
||||
pico_generate_pio_header(Mon_Projet ${CMAKE_CURRENT_LIST_DIR}/quadrature_encoder.pio)
|
||||
|
||||
target_include_directories(Mon_Projet PRIVATE VL53L8CX_ULD_API/inc/)
|
||||
target_include_directories(Mon_Projet PRIVATE ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
target_link_libraries(Mon_Projet
|
||||
hardware_adc
|
||||
@ -53,6 +55,7 @@ target_link_libraries(Mon_Projet
|
||||
hardware_pio
|
||||
pico_stdlib
|
||||
pico_multicore
|
||||
pico_cyw43_arch_lwip_threadsafe_background
|
||||
)
|
||||
|
||||
pico_enable_stdio_usb(Mon_Projet 1)
|
||||
|
||||
164
Wifi.c
Normal file
164
Wifi.c
Normal file
@ -0,0 +1,164 @@
|
||||
#include "Wifi.h"
|
||||
#include <string.h>
|
||||
#include "pico/cyw43_arch.h"
|
||||
#include "lwip/etharp.h"
|
||||
#include "lwip/ethip6.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "lwip/igmp.h"
|
||||
#include "lwip/tcpip.h"
|
||||
#include "netif/ethernet.h"
|
||||
#include <pico/lwip_nosys.h>
|
||||
// Si le fichier n'existe pas, créez-le à partir du modèle "wifi_settings.h.default"
|
||||
#include "wifi_settings.h"
|
||||
|
||||
#define BEACON_MSG_LEN_MAX 500
|
||||
#define UDP_CLIENT_PORT 1234
|
||||
|
||||
struct udp_pcb* pcb;
|
||||
struct udp_pcb * pcb_r;
|
||||
ip_addr_t my_ip_addr, host_ip_addr;
|
||||
|
||||
char udp_buffer_r[UDP_BUFFER_LENGTH];
|
||||
unsigned int udp_buffer_r_index = 0;
|
||||
|
||||
void udp_receive_put_in_buffer(char c){
|
||||
if(udp_buffer_r_index + 1< UDP_BUFFER_LENGTH){
|
||||
udp_buffer_r[udp_buffer_r_index] = c;
|
||||
udp_buffer_r_index++;
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief Copie les données reçues par UDP dans le tampon et renvoie le nombre de données copiées
|
||||
/// @param tampon qui va contenir les données
|
||||
/// @return Nombre de données dans le tampon
|
||||
int udp_receive_get_from_buffer(char* tampon){
|
||||
unsigned int taille_tampon;
|
||||
if( udp_buffer_r_index > 0){
|
||||
taille_tampon = udp_buffer_r_index;
|
||||
memcpy(tampon, udp_buffer_r, taille_tampon);
|
||||
udp_buffer_r_index = 0;
|
||||
return taille_tampon;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void udp_receive_callback(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port){
|
||||
for(int i=0; i < p->len; i++){
|
||||
udp_receive_put_in_buffer(((char*)p->payload)[i]);
|
||||
}
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
||||
int UDP_client_init(void){
|
||||
pcb_r = udp_new();
|
||||
if(pcb_r == NULL)
|
||||
{
|
||||
puts("Error creating UDP client");
|
||||
return -1;
|
||||
}
|
||||
udp_recv(pcb_r, udp_receive_callback, NULL);
|
||||
err_t err = udp_bind(pcb_r, IP_ADDR_ANY, UDP_CLIENT_PORT);
|
||||
if(err)
|
||||
{
|
||||
printf("Error binding UDP client: %d\n", err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("UDP client started on port %d\n", UDP_CLIENT_PORT);
|
||||
|
||||
}
|
||||
|
||||
int Wifi_init(void){
|
||||
if (cyw43_arch_init()) {
|
||||
printf("failed to initialise\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
cyw43_arch_enable_sta_mode();
|
||||
|
||||
printf("Connecting to Wi-Fi...\n");
|
||||
while (cyw43_arch_wifi_connect_timeout_ms(MY_WIFI_SSID, MY_WIFI_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 30000)) {
|
||||
printf("failed to connect.\n");
|
||||
}
|
||||
printf("Connected.\n");
|
||||
|
||||
pcb = udp_new();
|
||||
ipaddr_aton(BEACON_TARGET, &my_ip_addr);
|
||||
|
||||
|
||||
UDP_client_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Wifi_udp_send_data(char * message, unsigned int size){
|
||||
static int counter = 0;
|
||||
|
||||
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, BEACON_MSG_LEN_MAX+1, PBUF_RAM);
|
||||
char *req = (char *)p->payload;
|
||||
memset(req, 0, BEACON_MSG_LEN_MAX+1);
|
||||
|
||||
if(size <BEACON_MSG_LEN_MAX){
|
||||
memcpy(req, message, size);
|
||||
}else{
|
||||
printf("Error: size >= BEACON_MSG_LEN_MAX\n");
|
||||
}
|
||||
|
||||
err_t er = udp_sendto(pcb, p, &my_ip_addr, 1234);
|
||||
|
||||
pbuf_free(p);
|
||||
if (er != ERR_OK) {
|
||||
printf("Failed to send UDP packet! error=%d", er);
|
||||
} else {
|
||||
// printf("Sent packet %d\n", counter);
|
||||
counter++;
|
||||
}
|
||||
|
||||
// Note in practice for this simple UDP transmitter,
|
||||
// the end result for both background and poll is the same
|
||||
|
||||
#if PICO_CYW43_ARCH_POLL
|
||||
// if you are using pico_cyw43_arch_poll, then you must poll periodically from your
|
||||
// main loop (not from a timer) to check for Wi-Fi driver or lwIP work that needs to be done.
|
||||
cyw43_arch_poll();
|
||||
#else
|
||||
// if you are not using pico_cyw43_arch_poll, then WiFI driver and lwIP work
|
||||
// is done via interrupt in the background. This sleep is just an example of some (blocking)
|
||||
// work you might be doing.
|
||||
// sleep_ms(BEACON_INTERVAL_MS);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Wifi_udp_send_string(char * message){
|
||||
static int counter = 0;
|
||||
|
||||
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, BEACON_MSG_LEN_MAX+1, PBUF_RAM);
|
||||
char *req = (char *)p->payload;
|
||||
memset(req, 0, BEACON_MSG_LEN_MAX+1);
|
||||
|
||||
snprintf(req, BEACON_MSG_LEN_MAX, "%s", message);
|
||||
|
||||
err_t er = udp_sendto(pcb, p, &my_ip_addr, 1234);
|
||||
//er |= udp_sendto(pcb, p, &my_ip_addr, 1234);
|
||||
|
||||
pbuf_free(p);
|
||||
if (er != ERR_OK) {
|
||||
printf("Failed to send UDP packet! error=%d", er);
|
||||
} else {
|
||||
// printf("Sent packet %d\n", counter);
|
||||
counter++;
|
||||
}
|
||||
|
||||
// Note in practice for this simple UDP transmitter,
|
||||
// the end result for both background and poll is the same
|
||||
|
||||
#if PICO_CYW43_ARCH_POLL
|
||||
// if you are using pico_cyw43_arch_poll, then you must poll periodically from your
|
||||
// main loop (not from a timer) to check for Wi-Fi driver or lwIP work that needs to be done.
|
||||
cyw43_arch_poll();
|
||||
#else
|
||||
// if you are not using pico_cyw43_arch_poll, then WiFI driver and lwIP work
|
||||
// is done via interrupt in the background. This sleep is just an example of some (blocking)
|
||||
// work you might be doing.
|
||||
// sleep_ms(BEACON_INTERVAL_MS);
|
||||
#endif
|
||||
}
|
||||
6
Wifi.h
Normal file
6
Wifi.h
Normal file
@ -0,0 +1,6 @@
|
||||
#define UDP_BUFFER_LENGTH 1024
|
||||
|
||||
int Wifi_init(void);
|
||||
void Wifi_udp_send_string(char * message);
|
||||
void Wifi_udp_send_data(char * message, unsigned int size);
|
||||
int udp_receive_get_from_buffer(char * );
|
||||
@ -2,6 +2,7 @@
|
||||
#include <stdio.h>
|
||||
#include "communication.h"
|
||||
#include "messagerie.h"
|
||||
#include "Wifi.h"
|
||||
#include "tusb.h"
|
||||
|
||||
#define TAMPON_TAILLE 1020
|
||||
@ -43,31 +44,21 @@ void augmente_index(unsigned int *index, unsigned int offset){
|
||||
/// et analyse si un message valide a été reçu.
|
||||
void communication_reception_message(){
|
||||
int input_char;
|
||||
char tampon_reception_udp[UDP_BUFFER_LENGTH];
|
||||
int chaîne_octets_reçus[TAMPON_TAILLE];
|
||||
unsigned int index_chaine_recue;
|
||||
unsigned int index_tampon;
|
||||
struct message_t message;
|
||||
// Si un caractère est reçu, ajout du caractère au tampon tournant
|
||||
|
||||
/// TODO: Tester le code suivant à la place de while get_char();
|
||||
/*
|
||||
char nb_recu=0;
|
||||
if(tud_cdc_available()){
|
||||
char tampon_usb[128];
|
||||
nb_recu = tud_cdc_read(tampon_usb, 128);
|
||||
// copie dans le tampon tournant
|
||||
for(int i=0; i<nb_recu; i++){
|
||||
input_char = tampon_usb[i];
|
||||
com_reception_buffer.index_tampon_ecriture++;
|
||||
if(com_reception_buffer.index_tampon_ecriture >= TAMPON_TAILLE){
|
||||
com_reception_buffer.index_tampon_ecriture = 0;
|
||||
}
|
||||
com_reception_buffer.tampon[com_reception_buffer.index_tampon_ecriture] = input_char;
|
||||
}
|
||||
}*/
|
||||
|
||||
input_char = stdio_getchar_timeout_us(0);
|
||||
while(input_char != PICO_ERROR_TIMEOUT){
|
||||
// input_char = stdio_getchar_timeout_us(0);
|
||||
//printf("Ajout tampon tournant\n");
|
||||
int nb_char = udp_receive_get_from_buffer(tampon_reception_udp);
|
||||
int current_nb_char = nb_char;
|
||||
//printf("nb_char %d\n", nb_char);
|
||||
while(current_nb_char > 0){
|
||||
input_char = tampon_reception_udp[nb_char - current_nb_char];
|
||||
current_nb_char--;
|
||||
com_reception_buffer.index_tampon_ecriture++;
|
||||
if(com_reception_buffer.index_tampon_ecriture >= TAMPON_TAILLE){
|
||||
com_reception_buffer.index_tampon_ecriture = 0;
|
||||
@ -75,11 +66,12 @@ void communication_reception_message(){
|
||||
com_reception_buffer.tampon[com_reception_buffer.index_tampon_ecriture] = input_char;
|
||||
|
||||
// Caractère suivant ?
|
||||
input_char = stdio_getchar_timeout_us(0);
|
||||
//input_char = stdio_getchar_timeout_us(0);
|
||||
}
|
||||
|
||||
// Copie du tampon tournant dans une chaine
|
||||
// Parce que c'est plus simple à traiter
|
||||
// printf("Copie, index_tampon:%d, index_tampon_ecriture:%d\n", index_tampon, com_reception_buffer.index_tampon_ecriture);
|
||||
index_chaine_recue = 0;
|
||||
index_tampon = com_reception_buffer.index_tampon_lecture;
|
||||
if(index_tampon != com_reception_buffer.index_tampon_ecriture){
|
||||
@ -92,12 +84,14 @@ void communication_reception_message(){
|
||||
index_chaine_recue++;
|
||||
increment_index(&index_tampon);
|
||||
}
|
||||
|
||||
|
||||
// Traitement
|
||||
// Si on trouve le début du message
|
||||
// Si on trouve la taille du message
|
||||
// Si le caractère de fin est bien à la fin du message
|
||||
int fin_message = 0;
|
||||
// printf("Traitement, index_chaine_recue:%d\n", index_chaine_recue);
|
||||
for(int i=0; i<index_chaine_recue; i++){
|
||||
int index_fin_message = 0;
|
||||
// Com v2
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
// Changer le define en fonction qu'on soit sur les PAMIs ou sur le robot principal
|
||||
|
||||
#define ROBOT_PROPULSION_2026
|
||||
//#define ROBOT_TYPE_PAMI
|
||||
//#define ROBOT_PROPULSION_2026
|
||||
#define ROBOT_TYPE_PAMI
|
||||
|
||||
#ifndef ROBOT_PROPULSION_2026
|
||||
#ifndef ROBOT_TYPE_PAMI
|
||||
|
||||
10
lwipopts.h
Normal file
10
lwipopts.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef _LWIPOPTS_H
|
||||
#define _LWIPOPTS_H
|
||||
|
||||
// Generally you would define your own explicit list of lwIP options
|
||||
// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html)
|
||||
//
|
||||
// This example uses a common include to avoid repetition
|
||||
#include "lwipopts_examples_common.h"
|
||||
|
||||
#endif
|
||||
90
lwipopts_examples_common.h
Normal file
90
lwipopts_examples_common.h
Normal file
@ -0,0 +1,90 @@
|
||||
#ifndef _LWIPOPTS_EXAMPLE_COMMONH_H
|
||||
#define _LWIPOPTS_EXAMPLE_COMMONH_H
|
||||
|
||||
|
||||
// Common settings used in most of the pico_w examples
|
||||
// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details)
|
||||
|
||||
// allow override in some examples
|
||||
#ifndef NO_SYS
|
||||
#define NO_SYS 1
|
||||
#endif
|
||||
// allow override in some examples
|
||||
#ifndef LWIP_SOCKET
|
||||
#define LWIP_SOCKET 0
|
||||
#endif
|
||||
#if PICO_CYW43_ARCH_POLL
|
||||
#define MEM_LIBC_MALLOC 1
|
||||
#else
|
||||
// MEM_LIBC_MALLOC is incompatible with non polling versions
|
||||
#define MEM_LIBC_MALLOC 0
|
||||
#endif
|
||||
#define MEM_ALIGNMENT 4
|
||||
#define MEM_SIZE 4000
|
||||
#define MEMP_NUM_TCP_SEG 32
|
||||
#define MEMP_NUM_ARP_QUEUE 10
|
||||
#define PBUF_POOL_SIZE 24
|
||||
#define LWIP_ARP 1
|
||||
#define LWIP_ETHERNET 1
|
||||
#define LWIP_ICMP 1
|
||||
#define LWIP_RAW 1
|
||||
#define TCP_WND (8 * TCP_MSS)
|
||||
#define TCP_MSS 1460
|
||||
#define TCP_SND_BUF (8 * TCP_MSS)
|
||||
#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS))
|
||||
#define LWIP_NETIF_STATUS_CALLBACK 1
|
||||
#define LWIP_NETIF_LINK_CALLBACK 1
|
||||
#define LWIP_NETIF_HOSTNAME 1
|
||||
#define LWIP_NETCONN 0
|
||||
#define MEM_STATS 0
|
||||
#define SYS_STATS 0
|
||||
#define MEMP_STATS 0
|
||||
#define LINK_STATS 0
|
||||
// #define ETH_PAD_SIZE 2
|
||||
#define LWIP_CHKSUM_ALGORITHM 3
|
||||
#define LWIP_DHCP 1
|
||||
#define LWIP_IPV4 1
|
||||
#define LWIP_TCP 1
|
||||
#define LWIP_UDP 1
|
||||
#define LWIP_DNS 1
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
#define LWIP_NETIF_TX_SINGLE_PBUF 1
|
||||
#define DHCP_DOES_ARP_CHECK 0
|
||||
#define LWIP_DHCP_DOES_ACD_CHECK 0
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define LWIP_DEBUG 1
|
||||
#define LWIP_STATS 1
|
||||
#define LWIP_STATS_DISPLAY 1
|
||||
#endif
|
||||
|
||||
#define ETHARP_DEBUG LWIP_DBG_OFF
|
||||
#define NETIF_DEBUG LWIP_DBG_OFF
|
||||
#define PBUF_DEBUG LWIP_DBG_OFF
|
||||
#define API_LIB_DEBUG LWIP_DBG_OFF
|
||||
#define API_MSG_DEBUG LWIP_DBG_OFF
|
||||
#define SOCKETS_DEBUG LWIP_DBG_OFF
|
||||
#define ICMP_DEBUG LWIP_DBG_OFF
|
||||
#define INET_DEBUG LWIP_DBG_OFF
|
||||
#define IP_DEBUG LWIP_DBG_OFF
|
||||
#define IP_REASS_DEBUG LWIP_DBG_OFF
|
||||
#define RAW_DEBUG LWIP_DBG_OFF
|
||||
#define MEM_DEBUG LWIP_DBG_OFF
|
||||
#define MEMP_DEBUG LWIP_DBG_OFF
|
||||
#define SYS_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_RTO_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_CWND_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_WND_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_FR_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_RST_DEBUG LWIP_DBG_OFF
|
||||
#define UDP_DEBUG LWIP_DBG_OFF
|
||||
#define TCPIP_DEBUG LWIP_DBG_OFF
|
||||
#define PPP_DEBUG LWIP_DBG_OFF
|
||||
#define SLIP_DEBUG LWIP_DBG_OFF
|
||||
#define DHCP_DEBUG LWIP_DBG_OFF
|
||||
|
||||
#endif /* __LWIPOPTS_H__ */
|
||||
164
main.c
164
main.c
@ -24,6 +24,7 @@
|
||||
#include "Trajet.h"
|
||||
#include "VL53L8_2024.h"
|
||||
#include "vl53l8cx_api.h"
|
||||
#include "Wifi.h"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "QEI.h"
|
||||
@ -55,11 +56,18 @@ const uint32_t step_ms=1;
|
||||
#endif
|
||||
float distance1_mm=0, distance2_mm=0;
|
||||
|
||||
volatile char memoire_vl53L8[64];
|
||||
volatile uint8_t VL53L8CX_isReady;
|
||||
|
||||
// DEBUG
|
||||
extern float abscisse;
|
||||
extern struct point_xyo_t point;
|
||||
VL53L8CX_Configuration Dev;
|
||||
|
||||
uint64_t get_temps_us(){
|
||||
return to_us_since_boot(get_absolute_time());
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
VL53L8CX_ResultsData Results;
|
||||
@ -75,8 +83,26 @@ void main(void)
|
||||
#endif
|
||||
Localisation_init(get_identifiant());
|
||||
Trajet_init(get_identifiant());
|
||||
//i2c_maitre_init();
|
||||
|
||||
sleep_ms(3000);
|
||||
Wifi_init();
|
||||
sleep_ms(50);
|
||||
Wifi_udp_send_string("Demarrage:1\n");
|
||||
Wifi_udp_send_string("test:1\n");
|
||||
sleep_ms(50);
|
||||
Wifi_udp_send_string("Demarrage:1\n");
|
||||
Wifi_udp_send_string("test:1\n");
|
||||
sleep_ms(50);
|
||||
Wifi_udp_send_string("Demarrage:1\n");
|
||||
Wifi_udp_send_string("test:1\n");
|
||||
sleep_ms(50);
|
||||
Wifi_udp_send_data("\x01\x02\x03\x04\x05", 5);
|
||||
Wifi_udp_send_string("test:1\n");
|
||||
|
||||
#ifdef ROBOT_PROPULSION_2026
|
||||
#else
|
||||
i2c_maitre_init();
|
||||
#endif
|
||||
//Servomoteur_Init();
|
||||
|
||||
communication_init();
|
||||
@ -93,27 +119,34 @@ void main(void)
|
||||
|
||||
gpio_init(LED1PIN);
|
||||
gpio_set_dir(LED1PIN, GPIO_OUT );
|
||||
gpio_put(LED1PIN, 1);
|
||||
//gpio_put(LED1PIN, 1);
|
||||
|
||||
/*
|
||||
gpio_init(PICO_DEFAULT_LED_PIN);
|
||||
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT );
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, 1);
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, 1);*/
|
||||
|
||||
|
||||
|
||||
printf("Demarrage...\n");
|
||||
|
||||
|
||||
|
||||
// TODO: A remettre - quand on aura récupéré un capteur
|
||||
if(get_identifiant() != 0){
|
||||
//multicore_launch_core1(gestion_VL53L8CX);
|
||||
//multicore_launch_core1(gestion_affichage);
|
||||
}else{
|
||||
//multicore_launch_core1(gestion_affichage);
|
||||
}
|
||||
|
||||
|
||||
#ifdef ROBOT_PROPULSION_2026
|
||||
#else
|
||||
VL53L8_init(&Dev);
|
||||
sleep_ms(100);
|
||||
VL53L8_lecture( &Dev, &Results); // une première lecture
|
||||
|
||||
//if(get_identifiant() != 0){
|
||||
multicore_launch_core1(gestion_VL53L8CX);
|
||||
//}else{
|
||||
//multicore_launch_core1(gestion_affichage);
|
||||
//}
|
||||
#endif
|
||||
gpio_put(LED1PIN, 1);
|
||||
//printf("Demarrage...\n");
|
||||
|
||||
|
||||
enum etat_trajet_t etat_trajet=TRAJET_EN_COURS;
|
||||
struct trajectoire_t trajectoire;
|
||||
@ -121,17 +154,23 @@ void main(void)
|
||||
//Trajet_config(TRAJECT_CONFIG_STD);
|
||||
Trajet_config(600, 300);
|
||||
|
||||
float distance_obstacle;
|
||||
|
||||
uint8_t status, isReady;
|
||||
|
||||
|
||||
while(1){
|
||||
|
||||
|
||||
communication_reception_message();
|
||||
|
||||
if(messagerie_message_disponible()){
|
||||
|
||||
uint8_t id_carte, registre;
|
||||
while(messagerie_message_disponible()){
|
||||
message = messagerie_get_message();
|
||||
|
||||
|
||||
if(message.type == 'b'){
|
||||
|
||||
switch(message.donnees[0]){
|
||||
case 'r': // réception de données
|
||||
// Reception de données
|
||||
@ -170,7 +209,7 @@ void main(void)
|
||||
}
|
||||
if(mise_a_jour_mode){
|
||||
get_données_reçues(&mode, sizeof(mode), REG_PROPULSION_MODE);
|
||||
//rintf("mode:%d\n", mode);
|
||||
printf("mode:%d\n", mode);
|
||||
}
|
||||
if(mise_a_jour_pwm){
|
||||
struct msg_propulsion_pwm_t msg_propulsion_pwm;
|
||||
@ -235,44 +274,54 @@ void main(void)
|
||||
id_carte = message.donnees[1];
|
||||
registre = message.donnees[2];
|
||||
if(id_carte == 'D'){
|
||||
if(message.donnees[4] > 0 && message.donnees[4] < 30){
|
||||
//printf("LED ON\n");
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, 1);
|
||||
}else{
|
||||
//printf("LED OFF\n");
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, 0);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
//printf("Demande donnees\n");
|
||||
char message_envoi_udp[500];
|
||||
// Demande de données
|
||||
memcpy(&message_applicatif, message.donnees, message.taille_donnees);
|
||||
// printf("id_carte:%c %d\n", message_applicatif.id_carte, message_applicatif.id_carte);
|
||||
// printf("adresse registre:%d\n", message_applicatif.adresse_registre, message_applicatif.id_carte);
|
||||
// printf("taille:%d\n", message_applicatif.taille_donnees, message_applicatif.taille_donnees);
|
||||
stdio_putchar_raw(0xFF);
|
||||
stdio_putchar_raw(0xFF);
|
||||
stdio_putchar_raw('P');
|
||||
stdio_putchar_raw(message_applicatif.taille_donnees+1);
|
||||
for(int i=0; i<message_applicatif.taille_donnees; i++ ){
|
||||
stdio_putchar_raw(memoire_echange[message_applicatif.adresse_registre + i]);
|
||||
|
||||
message_envoi_udp[0] = 0xFF;
|
||||
message_envoi_udp[1] = 0xFF;
|
||||
if(message_applicatif.id_carte == 'P'){
|
||||
// Demande des données liées au déplacement
|
||||
message_envoi_udp[2] = 'P';
|
||||
message_envoi_udp[3] = message_applicatif.taille_donnees+1;
|
||||
|
||||
for(int i=0; i<message_applicatif.taille_donnees; i++ ){
|
||||
message_envoi_udp[4+i] = memoire_echange[message_applicatif.adresse_registre + i];
|
||||
}
|
||||
message_envoi_udp[4+message_applicatif.taille_donnees] = 0x00;
|
||||
Wifi_udp_send_data(message_envoi_udp, 4+message_applicatif.taille_donnees + 1);
|
||||
}else if(message_applicatif.id_carte == 'V'){
|
||||
// Demande des données liées au VL53L8
|
||||
message_envoi_udp[2] = 'V';
|
||||
message_envoi_udp[3] = message_applicatif.taille_donnees+1;
|
||||
for(int i=0; i<message_applicatif.taille_donnees; i++ ){
|
||||
message_envoi_udp[4+i] = memoire_vl53L8[i];
|
||||
}
|
||||
message_envoi_udp[4+message_applicatif.taille_donnees] = 0x00;
|
||||
Wifi_udp_send_data(message_envoi_udp, 4+message_applicatif.taille_donnees + 1);
|
||||
}
|
||||
stdio_putchar_raw(0x00);
|
||||
stdio_putchar_raw('\n');
|
||||
break;
|
||||
default:
|
||||
//printf("Message inconnu: %d %c\n", message.donnees[0], message.donnees[0]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//printf(">temps_reception:%lld\n", current_time_us - start_time_us);
|
||||
//printf(">nb_message:%u\n",nb_message);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Fin du match
|
||||
|
||||
if(temps_ms != Temps_get_temps_ms()){
|
||||
|
||||
if(Temps_get_temps_ms() - temps_ms > 20){
|
||||
/// PANIC
|
||||
struct msg_propulsion_position_t msg_propulsion_position;
|
||||
@ -280,10 +329,11 @@ void main(void)
|
||||
msg_propulsion_position.position_y_mm = 0;
|
||||
msg_propulsion_position.orientation_rad = 0;
|
||||
mise_données_dans_échange((uint8_t*) &msg_propulsion_position, sizeof(msg_propulsion_position), REG_PROPULSION_POSITION);
|
||||
printf("panic\n");
|
||||
|
||||
Moteur_Stop();
|
||||
temps_ms = Temps_get_temps_ms();
|
||||
continue;
|
||||
|
||||
}
|
||||
temps_ms = Temps_get_temps_ms();
|
||||
if(temps_ms % step_ms == 0){
|
||||
@ -297,10 +347,6 @@ void main(void)
|
||||
Moteur_Stop();
|
||||
break;
|
||||
case 1:
|
||||
/*
|
||||
get_données_reçues((uint8_t *) &msg_propulsion_pwm, sizeof(msg_propulsion_pwm), REG_PROPULSION_PWM);
|
||||
Moteur_SetVitesse(MOTEUR_A, msg_propulsion_pwm.pwm_gauche);
|
||||
Moteur_SetVitesse(MOTEUR_B, msg_propulsion_pwm.pwm_droit);*/
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
@ -340,14 +386,14 @@ void main(void)
|
||||
//printf("x_mm:%.2f, y_mm:%.2f\n", position.x_mm, position.y_mm);
|
||||
|
||||
//gestion_PAMI(step_ms, &asser_pos);
|
||||
/*if(asser_pos){
|
||||
AsserMoteur_Gestion(step_ms);
|
||||
}*/
|
||||
// Récupération des valeurs pour les mettre dans la mémoire d'échange
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -426,18 +472,36 @@ void gestion_PAMI(uint32_t step_ms, int * asser_pos){
|
||||
void gestion_VL53L8CX(void){
|
||||
VL53L8CX_ResultsData Results;
|
||||
float distance_obstacle;
|
||||
VL53L8_init(&Dev);
|
||||
/*VL53L8_init(&Dev);
|
||||
sleep_ms(100);
|
||||
VL53L8_lecture( &Dev, &Results); // une première lecture
|
||||
VL53L8_lecture( &Dev, &Results); // une première lecture */
|
||||
uint8_t status, isReady;
|
||||
VL53L8CX_isReady = 1;
|
||||
while(1){
|
||||
status = vl53l8cx_check_data_ready(&Dev, &isReady);
|
||||
if(isReady){
|
||||
VL53L8_lecture( &Dev, &Results);
|
||||
VL53L8_min_distance(Results, &distance_obstacle);
|
||||
Trajet_set_obstacle_mm(distance_obstacle);
|
||||
if(status){
|
||||
//printf(">status:%d\n", status);
|
||||
}
|
||||
affichage();
|
||||
if(isReady){
|
||||
//printf("Ready\n");
|
||||
VL53L8_lecture( &Dev, &Results);
|
||||
//printf("Trajet 1\n");
|
||||
VL53L8_min_distance(Results, &distance_obstacle);
|
||||
//printf("Trajet 2\n");
|
||||
Trajet_set_obstacle_mm(distance_obstacle);
|
||||
//printf("Trajet 3\n");
|
||||
|
||||
for(int i=0; i<64; i++){
|
||||
//int distance_cm = Results.distance_mm[i] / 10;
|
||||
int distance_cm = Results.distance_mm[i];
|
||||
if(distance_cm > 200){
|
||||
distance_cm = 250;
|
||||
}
|
||||
memoire_vl53L8[i] = distance_cm;
|
||||
}
|
||||
/*printf("VL:%3d %3d %3d %3d\n", memoire_vl53L8[0], memoire_vl53L8[1], memoire_vl53L8[2], memoire_vl53L8[3]);*/
|
||||
}
|
||||
//affichage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#include <string.h>
|
||||
#include "messagerie_applicative.h"
|
||||
|
||||
uint8_t memoire_echange[200];
|
||||
uint8_t memoire_echange[0xFF];
|
||||
|
||||
|
||||
|
||||
@ -14,11 +14,11 @@ bool mise_a_jour_trajectoire = false;
|
||||
bool mise_a_jour_config_trajet = false;
|
||||
bool mise_a_jour_cde_inv_traj = false;
|
||||
|
||||
void get_données_reçues(uint8_t * dst, unsigned int taille, unsigned int registre){
|
||||
void get_données_reçues(uint8_t * dst, unsigned int taille, uint8_t registre){
|
||||
memcpy(dst, &(memoire_echange[registre]), taille);
|
||||
}
|
||||
|
||||
void mise_données_dans_échange(uint8_t * source, unsigned int taille, unsigned int registre){
|
||||
void mise_données_dans_échange(uint8_t * source, unsigned int taille, uint8_t registre){
|
||||
memcpy(&(memoire_echange[registre]), source, taille);
|
||||
}
|
||||
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
void écriture_données(unsigned int adresse, uint8_t donnée);
|
||||
void get_données_reçues(uint8_t * dst, unsigned int taille, unsigned int registre);
|
||||
void mise_données_dans_échange(uint8_t * source, unsigned int taille, unsigned int registre);
|
||||
void get_données_reçues(uint8_t * dst, unsigned int taille, uint8_t registre);
|
||||
void mise_données_dans_échange(uint8_t * source, unsigned int taille, uint8_t registre);
|
||||
|
||||
extern uint8_t memoire_echange[];
|
||||
|
||||
|
||||
11
wifi_settings.h
Normal file
11
wifi_settings.h
Normal file
@ -0,0 +1,11 @@
|
||||
#define MY_WIFI_SSID "Xperia 10 III"
|
||||
#define MY_WIFI_PASSWORD "keuronde"
|
||||
|
||||
#define UDP_PORT 47269
|
||||
|
||||
//#define BEACON_TARGET "192.168.1.58"
|
||||
|
||||
#define BEACON_TARGET "172.28.172.11"
|
||||
|
||||
/*#define MY_WIFI_SSID "Livebox-A040"
|
||||
#define MY_WIFI_PASSWORD "QkqoXCPt6UgvaUAWmq"*/
|
||||
9
wifi_settings.h.default
Normal file
9
wifi_settings.h.default
Normal file
@ -0,0 +1,9 @@
|
||||
// Copier ce fichier en "wifi_settings.h" et renseignez vos identifiants WiFi.
|
||||
// Le port est le port par défaut de Teleplot
|
||||
// BEACON_TARGET est l'IP ou l'adresse du serveur Teleplot
|
||||
|
||||
#define MY_WIFI_SSID "My_SSID"
|
||||
#define MY_WIFI_PASSWORD "My_WiFi_Password"
|
||||
|
||||
#define UDP_PORT 47269
|
||||
#define BEACON_TARGET "192.168.1.2"
|
||||
Loading…
Reference in New Issue
Block a user