Commit 87a85ccd authored by Vojtěch Szotkowski's avatar Vojtěch Szotkowski
Browse files

Fix turn direction and add interrupt prio

parent fbfd108e
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
#define UART_RX_PIN   16
#define RX_BUF_SIZE   64
#define TX_BUF_SIZE   1024
#define STRUCT_SIZE_FROM_MCU 566
#define STRUCT_SIZE_FROM_MCU 576
#define BAUDRATE 2000000

volatile bool udp_client_running = false;
@@ -55,6 +55,8 @@ void udp_server_task(void *pvParameters) {
            rx_buffer[len] = '\0';
            ESP_LOGI(TAG, "Received[%d]: %d, %d, %d", len, rx_buffer[0], rx_buffer[1], rx_buffer[2]);
            uart_write_bytes(UART_NUM, rx_buffer, len);  // Send to UART
        } else {
            ESP_LOGI(TAG, "recv len: %d", len);
        }
    }

+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ typedef struct {
    struct Servo {
        uint16_t pulse_width_us;    // SET
        uint16_t midpoint_us;    	// CFG
        uint16_t side_range_us;    	// CFG
        uint16_t c_lin;             // CFG
        uint16_t c_sq;              // CFG
        uint16_t c_thresh;          // CFG
+10 −7
Original line number Diff line number Diff line
@@ -51,14 +51,15 @@ class Camera:
class Servo:
    pulse_width_us: int = 0
    midpoint_us: int = 0
    side_range_us: int = 0
    c_lin: int = 0
    c_sq: int = 0
    c_thresh: int = 0

    cfg_members: List[str] = field(init=False)
    cfg_format: str = 'HHHH'
    cfg_format: str = 'HHHHH'
    def __post_init__(self):
        self.cfg_members: List[str] = ['midpoint_us', 'c_lin', 'c_sq', 'c_thresh']
        self.cfg_members: List[str] = ['midpoint_us', 'side_range_us', 'c_lin', 'c_sq', 'c_thresh']

@dataclass
class Regl:
@@ -101,15 +102,17 @@ class ConfigStruct:

    @staticmethod
    def deserialize(data: bytes) -> "ConfigStruct":
        fmt = "128H 128H B B B B B B B B H H B B B B B B H H H H H H H H H H H H H H H H H H H H H H "
        fmt = "128H 128H B B B B B B B B H H B B B B B B H H H H H H H H H H H H H H H H H H H H H H H "
        unpacked = struct.unpack(fmt, data)
        return ConfigStruct(
            camera_1_frame=list(unpacked[0:128]),
            camera_2_frame=list(unpacked[128:256]),
            general=General(*unpacked[256:266]),
            camera=Camera(*unpacked[266:276]),
            servo=Servo(*unpacked[276:281]),
            regl=Regl(*unpacked[281:289]),
            sonic=Sonic(*unpacked[289:293]),
            separator=unpacked[293],
            servo=Servo(*unpacked[276:282]),
            regl=Regl(*unpacked[282:290]),
            sonic=Sonic(*unpacked[290:294]),
            separator=unpacked[294],
        )

print(struct.calcsize("128H 128H B B B B B B B B H H B B B B B B H H H H H H H H H H H H H H H H H H H H H H H "))
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ from keyboard import Keyboard
# Wifi
UDP_IP = "0.0.0.0"  # Listen on all available interfaces
UDP_PORT = 3333
BYTES_BRCAST = 574
BYTES_BRCAST = 576
car_ip = "0.0.0.0"

# Fps
@@ -165,7 +165,7 @@ def set_servo(time_us):
    if CarState(config_struct.general.state) != CarState.MANUAL:
        logging.debug("Cannot set servo - not in state: manual")
        return
    elif time_us < 1300 or time_us > 1700:
    elif time_us < 1100 or time_us > 1900:
        logging.debug("Wont set servo - out of range value: %dus", time_us)
        return
    else:
+11 −5
Original line number Diff line number Diff line
@@ -133,8 +133,8 @@ instance:
        - interrupt_channel:
          - IRQn: 'EDMA_0_CH0_IRQn'
          - enable_interrrupt: 'noInit'
          - enable_priority: 'false'
          - priority: '0'
          - enable_priority: 'true'
          - priority: '2'
          - enable_custom_name: 'false'
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
@@ -151,6 +151,8 @@ static void DMA0_init(void) {
  /* Channel CH0 initialization */
  /* Set the kDma0RequestMuxAdc0FifoARequest request */
  EDMA_SetChannelMux(DMA0_DMA_BASEADDR, DMA0_CH0_DMA_CHANNEL, DMA0_CH0_DMA_REQUEST);
  /* Interrupt vector EDMA_0_CH0_IRQn priority settings in the NVIC. */
  NVIC_SetPriority(DMA0_DMA_CH_INT_DONE_0_IRQN, DMA0_DMA_CH_INT_DONE_0_IRQ_PRIORITY);
  /* Interrupt DMA0_DMA_CH_INT_DONE_0_IRQN request in the NVIC is not initialized (disabled by default). */
  /* It can be enabled later by EnableIRQ(DMA0_DMA_CH_INT_DONE_0_IRQN); function call. */
  /* DMA0 hardware channel 0 request auto stop */
@@ -581,8 +583,8 @@ instance:
        - common_interrupt:
          - IRQn: 'FLEXPWM1_SUBMODULE2_IRQn'
          - enable_interrrupt: 'enabled'
          - enable_priority: 'false'
          - priority: '0'
          - enable_priority: 'true'
          - priority: '1'
          - enable_custom_name: 'false'
    - faultChannels:
      - 0:
@@ -721,6 +723,8 @@ static void PWM1_init(void) {
  PWM_OutputTriggerEnable(PWM1_PERIPHERAL, PWM1_SM2, kPWM_ValueRegister_3, true);
  /* Enable interrupts from main config of the submodule SM2 */
  PWM_EnableInterrupts(PWM1_PERIPHERAL, PWM1_SM2, (kPWM_CompareVal0InterruptEnable));
  /* Interrupt vector FLEXPWM1_SUBMODULE2_IRQn priority settings in the NVIC. */
  NVIC_SetPriority(PWM1_COMMON_SM_2_IRQN, PWM1_COMMON_SM_2_IRQ_PRIORITY);
  /* Enable interrupt PWM1_COMMON_SM_2_IRQN request in the NVIC */
  EnableIRQ(PWM1_COMMON_SM_2_IRQN);
}
@@ -797,7 +801,7 @@ instance:
      - user_data: ''
    - interrupt_rx_tx:
      - IRQn: 'LP_FLEXCOMM1_IRQn'
      - enable_priority: 'false'
      - enable_priority: 'true'
      - priority: '0'
  - fsl_lpuart:
    - lpuartConfig:
@@ -899,6 +903,8 @@ lpuart_transfer_t LP_FLEXCOMM1_rxTransfer = {
static void LP_FLEXCOMM1_init(void) {
  LPUART_Init(LP_FLEXCOMM1_PERIPHERAL, &LP_FLEXCOMM1_config, LP_FLEXCOMM1_CLOCK_SOURCE);
  LPUART_TransferCreateHandle(LP_FLEXCOMM1_PERIPHERAL, &LP_FLEXCOMM1_handle, LPUART_UserCallback, NULL);
  /* Interrupt vector LP_FLEXCOMM1_IRQn priority settings in the NVIC. */
  NVIC_SetPriority(LP_FLEXCOMM1_FLEXCOMM_IRQN, LP_FLEXCOMM1_FLEXCOMM_IRQ_PRIORITY);
}

/***********************************************************************************************************************
Loading