Replies: 1 comment
-
I have successfully managed to modified my code and I was able to make it build |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I'm working on an AGV that communicates via ESP32 module with the hoverboard firmware. I'm trying to add the includ path from the ESP-IDF driver component (Located at:/microros_ws/firmware/toolchain/esp-idf/components/driver/include/driver) to my code. Where is the CmakeFile.txt wich consist the paths which the app.c recognize or what should I modify for the project to recognize this path? Thank you!
My app.c code follows:
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "driver/uart.h"
#include <rcl/rcl.h>
#include <rcl/error_handling.h>
#include <std_msgs/msg/int32.h>
#include <rclc/rclc.h>
#include <rclc/executor.h>
#ifdef ESP_PLATFORM
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#endif
#define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){printf("Failed status on line %d: %d. Aborting.\n",LINE,(int)temp_rc);vTaskDelete(NULL);}}
#define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){printf("Failed status on line %d: %d. Continuing.\n",LINE,(int)temp_rc);}}
// ########################## DEFINES ##########################
#define HOVER_SERIAL_BAUD 9600 // [-] Baud rate for HoverSerial (used to communicate with the hoverboard)
#define SERIAL_BAUD 115200 // [-] Baud rate for built-in Serial (used for the Serial Monitor)
#define START_FRAME 0xABCD // [-] Start frame definition for reliable serial communication
#define TIME_SEND 160 // [ms] Sending time interval
#define SPEED_MAX_TEST 300 // [-] Maximum speed for testing
#define SPEED_STEP 20 // [-] Speed step
#define UART_NUM_2 (2) /*!< UART port 2 /
#define UART_PIN_NO_CHANGE (-1) /!< Constant for uart_set_pin function which indicates that UART pin should not be changed */
#define BUF_SIZE 1024
#define TXD2 17
#define RXD2 16
int16_t uSteer, uSpeed; // declaration
uart_config_t uart_config = {
.baud_rate = HOVER_SERIAL_BAUD, // using the defined constant here
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE
};
// Setup UART
uart_param_config(UART_NUM_2, &uart_config);
uart_set_pin(UART_NUM_2, TXD2, RXD2, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
uart_driver_install(UART_NUM_2, BUF_SIZE * 2, 0, 0, NULL, 0);
typedef struct{
uint16_t start;
int16_t steer;
int16_t speed;
uint16_t checksum;
} SerialCommand;
SerialCommand Command;
typedef struct{
uint16_t start;
int16_t cmd1;
int16_t cmd2;
int16_t speedR_meas;
int16_t speedL_meas;
int16_t batVoltage;
int16_t boardTemp;
uint16_t cmdLed;
uint16_t checksum;
} SerialFeedback;
SerialFeedback Feedback;
SerialFeedback NewFeedback;
uint8_t idx = 0; // Index for new data pointer
uint16_t bufStartFrame; // Buffer Start Frame
uint8_t *p; // Pointer declaration for the new received data
uint8_t incomingByte;
uint8_t incomingBytePrev;
uint8_t agvSpeed = 250;
uint8_t agvSteer = 0;
rcl_publisher_t publisher;
std_msgs__msg__Int32 msg;
void Send(int16_t uSteer, int16_t uSpeed)
{
Command.start = (uint16_t)START_FRAME;
Command.steer = uSteer; /// - left // + right
Command.speed = uSpeed; /// - forw // + back
Command.checksum = (uint16_t)(Command.start ^ Command.steer ^ Command.speed);
// Serial2.write((uint8_t *) &Command, sizeof(Command));
// Serial2 is not available in the ESP-IDF, instead use uart_write_bytes as described in the ESP-IDF documentation.
//uart_write_bytes(UART_NUM_2, (uint8_t ) &Command, sizeof(Command));
uart_write_bytes(UART_NUM_2, (const char) &Command, sizeof(Command));
}
// Task function
void hoverboard_control_task(void *pvParameter)
{
// Your loop code here...
while (1)
{
// Receive command from somewhere
// For now, let's just use some test values
// In a real scenario, you might receive these values over UART, SPI, I2C, etc.
uSteer = 0; // Some test value
uSpeed = 0; // Some test value
}
void stopAgv()
{
Send(0, 0);
//uart_write_bytes(UART_NUM_2, (uint8_t ) &Command, sizeof(Command));
uart_write_bytes(UART_NUM_2, (const char) &Command, sizeof(Command));
}
void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
{
RCLC_UNUSED(last_call_time);
if (timer != NULL) {
uint8_t data[128]; // buffer for your data
int len = uart_read_bytes(UART_NUM_2, data, sizeof(data), 20 / portTICK_RATE_MS);
if (len > 0) {
for (int i = 0; i < len; i++) {
incomingBytePrev = incomingByte;
incomingByte = data[i];
}
void appMain(void * arg)
{
rcl_allocator_t allocator = rcl_get_default_allocator();
rclc_support_t support;
}
Beta Was this translation helpful? Give feedback.
All reactions