Updated pico files and udp communication
This commit is contained in:
parent
8df520c24c
commit
77eae511b2
|
|
@ -5,7 +5,7 @@
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"group": "build",
|
"group": "build",
|
||||||
|
|
||||||
"command": "mkdir -p build && cd build && cmake ../ && make",
|
"command": "mkdir -p build && cd build && cmake ../ && make -j $(nproc)",
|
||||||
|
|
||||||
"presentation": {
|
"presentation": {
|
||||||
"echo": true,
|
"echo": true,
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"group": "build",
|
"group": "build",
|
||||||
|
|
||||||
"command": "mkdir -p build && cd build && cmake ../ && make Flash",
|
"command": "mkdir -p build && cd build && cmake ../ && make -j $(nproc) Flash",
|
||||||
|
|
||||||
"presentation": {
|
"presentation": {
|
||||||
"echo": true,
|
"echo": true,
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ add_executable(main_controller
|
||||||
src/i2c/mcp23017.c
|
src/i2c/mcp23017.c
|
||||||
src/wifi/wifi_operator.c
|
src/wifi/wifi_operator.c
|
||||||
src/wifi/udp_client.c
|
src/wifi/udp_client.c
|
||||||
src/wifi/udp_payload.c
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(main_controller PRIVATE
|
target_include_directories(main_controller PRIVATE
|
||||||
|
|
@ -36,7 +35,6 @@ target_link_libraries(main_controller
|
||||||
pico_stdlib
|
pico_stdlib
|
||||||
hardware_i2c
|
hardware_i2c
|
||||||
hardware_pwm
|
hardware_pwm
|
||||||
hardware_uart
|
|
||||||
pico_cyw43_arch_lwip_poll
|
pico_cyw43_arch_lwip_poll
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,28 @@
|
||||||
# This can be dropped into an external project to help locate this SDK
|
# This can be dropped into an external project to help locate this SDK
|
||||||
# It should be include()ed prior to project()
|
# It should be include()ed prior to project()
|
||||||
|
|
||||||
|
# Copyright 2020 (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
||||||
|
# following conditions are met:
|
||||||
|
#
|
||||||
|
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
||||||
|
# disclaimer.
|
||||||
|
#
|
||||||
|
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
|
||||||
|
# disclaimer in the documentation and/or other materials provided with the distribution.
|
||||||
|
#
|
||||||
|
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
|
||||||
|
# derived from this software without specific prior written permission.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
|
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
|
||||||
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
|
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
|
||||||
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
|
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
|
||||||
|
|
@ -18,9 +40,20 @@ if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_P
|
||||||
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
|
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_TAG} AND (NOT PICO_SDK_FETCH_FROM_GIT_TAG))
|
||||||
|
set(PICO_SDK_FETCH_FROM_GIT_TAG $ENV{PICO_SDK_FETCH_FROM_GIT_TAG})
|
||||||
|
message("Using PICO_SDK_FETCH_FROM_GIT_TAG from environment ('${PICO_SDK_FETCH_FROM_GIT_TAG}')")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (PICO_SDK_FETCH_FROM_GIT AND NOT PICO_SDK_FETCH_FROM_GIT_TAG)
|
||||||
|
set(PICO_SDK_FETCH_FROM_GIT_TAG "master")
|
||||||
|
message("Using master as default value for PICO_SDK_FETCH_FROM_GIT_TAG")
|
||||||
|
endif()
|
||||||
|
|
||||||
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
|
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
|
||||||
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
|
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
|
||||||
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
|
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
|
||||||
|
set(PICO_SDK_FETCH_FROM_GIT_TAG "${PICO_SDK_FETCH_FROM_GIT_TAG}" CACHE FILEPATH "release tag for SDK")
|
||||||
|
|
||||||
if (NOT PICO_SDK_PATH)
|
if (NOT PICO_SDK_PATH)
|
||||||
if (PICO_SDK_FETCH_FROM_GIT)
|
if (PICO_SDK_FETCH_FROM_GIT)
|
||||||
|
|
@ -32,11 +65,37 @@ if (NOT PICO_SDK_PATH)
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
pico_sdk
|
pico_sdk
|
||||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||||
GIT_TAG master
|
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
|
||||||
)
|
)
|
||||||
|
|
||||||
if (NOT pico_sdk)
|
if (NOT pico_sdk)
|
||||||
message("Downloading Raspberry Pi Pico SDK")
|
message("Downloading Raspberry Pi Pico SDK")
|
||||||
FetchContent_Populate(pico_sdk)
|
# GIT_SUBMODULES_RECURSE was added in 3.17
|
||||||
|
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
|
||||||
|
FetchContent_Populate(
|
||||||
|
pico_sdk
|
||||||
|
QUIET
|
||||||
|
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||||
|
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
|
||||||
|
GIT_SUBMODULES_RECURSE FALSE
|
||||||
|
|
||||||
|
SOURCE_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-src
|
||||||
|
BINARY_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-build
|
||||||
|
SUBBUILD_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-subbuild
|
||||||
|
)
|
||||||
|
else ()
|
||||||
|
FetchContent_Populate(
|
||||||
|
pico_sdk
|
||||||
|
QUIET
|
||||||
|
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||||
|
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
|
||||||
|
|
||||||
|
SOURCE_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-src
|
||||||
|
BINARY_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-build
|
||||||
|
SUBBUILD_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-subbuild
|
||||||
|
)
|
||||||
|
endif ()
|
||||||
|
|
||||||
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
|
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
|
||||||
endif ()
|
endif ()
|
||||||
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
|
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
|
||||||
|
|
|
||||||
|
|
@ -14,22 +14,23 @@ void robot_init(void)
|
||||||
|
|
||||||
stdio_init_all();
|
stdio_init_all();
|
||||||
|
|
||||||
if(cyw43_arch_init())
|
if(cyw43_arch_init_with_country(CYW43_COUNTRY_FRANCE))
|
||||||
robot.is_running = false;
|
robot.is_running = false;
|
||||||
|
|
||||||
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, true);
|
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, true);
|
||||||
|
|
||||||
i2c_master_init();
|
//i2c_master_init();
|
||||||
|
|
||||||
mcp23017_init();
|
//mcp23017_init();
|
||||||
|
|
||||||
gyro_init();
|
//gyro_init();
|
||||||
|
|
||||||
//gyro_calibrate();
|
//gyro_calibrate();
|
||||||
|
|
||||||
//motion_control_init();
|
//motion_control_init();
|
||||||
|
|
||||||
wifi_operator_init();
|
if(wifi_operator_init())
|
||||||
|
robot.is_running = false;
|
||||||
|
|
||||||
if(udp_client_init())
|
if(udp_client_init())
|
||||||
robot.is_running = false;
|
robot.is_running = false;
|
||||||
|
|
|
||||||
|
|
@ -21,18 +21,18 @@
|
||||||
#endif
|
#endif
|
||||||
#define MEM_ALIGNMENT 4
|
#define MEM_ALIGNMENT 4
|
||||||
#ifndef MEM_SIZE
|
#ifndef MEM_SIZE
|
||||||
#define MEM_SIZE 32768 // Augmenté pour plus de mémoire disponible
|
#define MEM_SIZE 4000
|
||||||
#endif
|
#endif
|
||||||
#define MEMP_NUM_TCP_SEG 32
|
#define MEMP_NUM_TCP_SEG 32
|
||||||
#define MEMP_NUM_ARP_QUEUE 10
|
#define MEMP_NUM_ARP_QUEUE 10
|
||||||
#define PBUF_POOL_SIZE 32 // Augmenté pour réduire les allocations
|
#define PBUF_POOL_SIZE 24
|
||||||
#define LWIP_ARP 1
|
#define LWIP_ARP 1
|
||||||
#define LWIP_ETHERNET 1
|
#define LWIP_ETHERNET 1
|
||||||
#define LWIP_ICMP 1
|
#define LWIP_ICMP 1
|
||||||
#define LWIP_RAW 1
|
#define LWIP_RAW 1
|
||||||
#define TCP_WND (16 * TCP_MSS) // Augmenté pour de meilleures performances
|
#define TCP_WND (8 * TCP_MSS)
|
||||||
#define TCP_MSS 1460
|
#define TCP_MSS 1460
|
||||||
#define TCP_SND_BUF (8 * TCP_MSS) // Augmenté pour de meilleures performances
|
#define TCP_SND_BUF (8 * TCP_MSS)
|
||||||
#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS))
|
#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS))
|
||||||
#define LWIP_NETIF_STATUS_CALLBACK 1
|
#define LWIP_NETIF_STATUS_CALLBACK 1
|
||||||
#define LWIP_NETIF_LINK_CALLBACK 1
|
#define LWIP_NETIF_LINK_CALLBACK 1
|
||||||
|
|
@ -44,8 +44,7 @@
|
||||||
#define LINK_STATS 0
|
#define LINK_STATS 0
|
||||||
// #define ETH_PAD_SIZE 2
|
// #define ETH_PAD_SIZE 2
|
||||||
#define LWIP_CHKSUM_ALGORITHM 3
|
#define LWIP_CHKSUM_ALGORITHM 3
|
||||||
#define LWIP_DHCP 0
|
#define LWIP_DHCP 1
|
||||||
#define LWIP_DHCP_SERVER 0
|
|
||||||
#define LWIP_IPV4 1
|
#define LWIP_IPV4 1
|
||||||
#define LWIP_TCP 1
|
#define LWIP_TCP 1
|
||||||
#define LWIP_UDP 1
|
#define LWIP_UDP 1
|
||||||
|
|
@ -90,8 +89,4 @@
|
||||||
#define SLIP_DEBUG LWIP_DBG_OFF
|
#define SLIP_DEBUG LWIP_DBG_OFF
|
||||||
#define DHCP_DEBUG LWIP_DBG_OFF
|
#define DHCP_DEBUG LWIP_DBG_OFF
|
||||||
|
|
||||||
#define SYS_LIGHTWEIGHT_PROT 1 // Protection pour le multicore
|
#endif /* __LWIPOPTS_H__ */
|
||||||
#define MEMP_NUM_PBUF 32 // Augmenté pour les buffers
|
|
||||||
#define ICMP_TTL 255 // Augmenté pour la fiabilité
|
|
||||||
|
|
||||||
#endif /* __LWIPOPTS_H__ */
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
#ifndef UDP_BUFFER_H
|
|
||||||
#define UDP_BUFFER_H
|
|
||||||
|
|
||||||
#include <pico.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <lwip/udp.h>
|
|
||||||
|
|
||||||
// Callback function for writing data when udp package received
|
|
||||||
void __not_in_flash_func(udp_client_message_handler)(uint8_t *payload, uint16_t len, const ip_addr_t *addr, u16_t port);
|
|
||||||
|
|
||||||
#endif // UDP_BUFFER_H
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
#ifndef WIFI_OPERATOR_H
|
#ifndef WIFI_OPERATOR_H
|
||||||
#define WIFI_OPERATOR_H
|
#define WIFI_OPERATOR_H
|
||||||
|
|
||||||
//#define WIFI_OPERATOR_SSID "RiombotiqueAP"
|
#define WIFI_OPERATOR_SSID "RiombotiqueAP"
|
||||||
//#define WIFI_OPERATOR_PASSWORD "x4ptSLpPuJFcpzbLEhDoZ5J7dz"
|
#define WIFI_OPERATOR_PASSWORD "x4ptSLpPuJFcpzbLEhDoZ5J7dz"
|
||||||
#define WIFI_OPERATOR_SSID "thinkpad-T440p"
|
//#define WIFI_OPERATOR_SSID "thinkpad-T440p"
|
||||||
#define WIFI_OPERATOR_PASSWORD "CDuKaka2000!"
|
//#define WIFI_OPERATOR_PASSWORD "CDuKaka2000!"
|
||||||
|
|
||||||
void wifi_operator_init(void);
|
int wifi_operator_init(void);
|
||||||
|
|
||||||
#endif // WIFI_OPERATOR_H
|
#endif // WIFI_OPERATOR_H
|
||||||
|
|
@ -1,14 +1,18 @@
|
||||||
#include "headers/udp_client.h"
|
#include "headers/udp_client.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "headers/udp_payload.h"
|
|
||||||
#include "headers/robot.h"
|
#include "headers/robot.h"
|
||||||
|
|
||||||
|
void __not_in_flash_func(message_callback)(uint8_t *payload, uint16_t len, const ip_addr_t *addr)
|
||||||
|
{
|
||||||
|
// RECEIVE ALL CONTROLLER DATA
|
||||||
|
}
|
||||||
|
|
||||||
// Default callback func
|
// Default callback func
|
||||||
static void __not_in_flash_func(default_message_callback)(uint8_t *payload, uint16_t len)
|
static inline void default_message_callback(uint8_t *payload, uint16_t len)
|
||||||
{
|
{
|
||||||
for(uint i = 0; i < len; i++)
|
for(uint i = 0; i < len; i++)
|
||||||
printf("payload[%d]=%d | ", i, payload[i]);
|
printf("payload[%d]=%d%s", i, payload[i], ((i + 1) == len) ? "" : " | ");
|
||||||
|
|
||||||
puts("\n");
|
puts("\n");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
#include "headers/udp_payload.h"
|
|
||||||
|
|
||||||
#include "i2c/headers/motors.h"
|
|
||||||
#include "headers/robot.h"
|
|
||||||
|
|
||||||
#define UDP_PAYLOAD_ANGLE_L_BYTE 0x00
|
|
||||||
#define UDP_PAYLOAD_ANGLE_H_BYTE 0x01
|
|
||||||
#define UDP_PAYLOAD_X_AXIS_SPEED_BYTE 0x02
|
|
||||||
#define UDP_PAYLOAD_Y_AXIS_SPEED_BYTE 0x03
|
|
||||||
|
|
||||||
void __not_in_flash_func(udp_client_message_handler)(uint8_t *payload, uint16_t len, const ip_addr_t *addr, u16_t port)
|
|
||||||
{
|
|
||||||
if(len != 16) return;
|
|
||||||
|
|
||||||
robot.motion_control_data.angle = ((payload[UDP_PAYLOAD_ANGLE_H_BYTE] << 8) | payload[UDP_PAYLOAD_ANGLE_L_BYTE]);
|
|
||||||
|
|
||||||
robot.motion_control_data.x_axis_speed = payload[UDP_PAYLOAD_X_AXIS_SPEED_BYTE];
|
|
||||||
robot.motion_control_data.y_axis_speed = payload[UDP_PAYLOAD_Y_AXIS_SPEED_BYTE];
|
|
||||||
/*
|
|
||||||
for(servo_motors_enum_t actual_servo_motor = SERVO_MOTOR1; actual_servo_motor < NB_SERVO_MOTORS; actual_servo_motor++)
|
|
||||||
{
|
|
||||||
const servo_motor_def_t *SERVO_MOTOR_DEF = &SERVO_MOTORS_DEFS[actual_servo_motor];
|
|
||||||
|
|
||||||
robot.motion_control_data.servo_motors_pos[actual_servo_motor] = payload[SERVO_MOTOR_DEF->buffer_reg_and_payload_byte];
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
@ -5,18 +5,20 @@
|
||||||
#include <lwip/netif.h>
|
#include <lwip/netif.h>
|
||||||
#include <lwip/ip4_addr.h>
|
#include <lwip/ip4_addr.h>
|
||||||
|
|
||||||
void wifi_operator_init(void)
|
int wifi_operator_init(void)
|
||||||
{
|
{
|
||||||
// Mode client
|
if(cyw43_wifi_pm(&cyw43_state, CYW43_NO_POWERSAVE_MODE))
|
||||||
|
{
|
||||||
|
puts("CYW43 no powersave mode failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Station mode
|
||||||
cyw43_arch_enable_sta_mode();
|
cyw43_arch_enable_sta_mode();
|
||||||
|
|
||||||
// Désactiver le mode d'économie d'énergie
|
|
||||||
cyw43_wifi_pm(&cyw43_state, CYW43_NO_POWERSAVE_MODE);
|
|
||||||
|
|
||||||
// Tentativs de connexion
|
|
||||||
for(int error_code = 1; error_code; )
|
for(int error_code = 1; error_code; )
|
||||||
{
|
{
|
||||||
puts("WiFi connection attempt");
|
printf("WiFi connection attempt to \"%s\"\n", WIFI_OPERATOR_SSID);
|
||||||
|
|
||||||
error_code = cyw43_arch_wifi_connect_timeout_ms(WIFI_OPERATOR_SSID, WIFI_OPERATOR_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 10000);
|
error_code = cyw43_arch_wifi_connect_timeout_ms(WIFI_OPERATOR_SSID, WIFI_OPERATOR_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 10000);
|
||||||
|
|
||||||
|
|
@ -43,5 +45,5 @@ void wifi_operator_init(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
puts("Connexion successfully etablished !");
|
puts("STA mode activated");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue