Hi everyone,
I’m trying to communicate an ESP32 with a Pixhawk 2.4.8 to obtain GPS data using the TELEM2 port on the Pixhawk. However, I am not receiving any messages, and the data does not appear in the MAVLink Inspector. Could anyone provide some advice?
Below are the latest parameters from the Pixhawk and the Arduino code:
full_parameters_08_08_24_16.55.param (13.9 KB)
#include <Marvelmind.h>
#include <MAVLink.h>
MarvelmindHedge hedge;
PositionValuePro positionVP;
RawIMUValue rIMUV;
FusionIMUValuePro fIMUVP;
char print_buffer[128];
const int res = 1; // Resolution to print values
float radiansToDegrees = 57.2957795f; // radians to degrees
float roll, pitch, yaw;
unsigned long t1;
const unsigned long period = 100;
long baudrate = 57600;
void setup() {
Serial.begin(baudrate); // Monitor serial
Serial2.begin(baudrate, SERIAL_8N1, 16, 17); // Configura Serial2 con los pines GPIO 16 (RX) y GPIO 17 (TX)
Serial1.begin(baudrate, SERIAL_8N1, 18, 19); // Configura Serial1 para la comunicación con la Pixhawk
hedge.begin(&Serial2);
t1 = millis();
}
void loop() {
hedge.read();
if (millis() - t1 > period) {
if (hedge.getPositionFromMarvelmindHedge(true, &positionVP)) {
Serial.print("Position Hedge: ");
Serial.print(" X=");
Serial.print(positionVP.x, res);
Serial.print(", Y=");
Serial.print(positionVP.y, res);
Serial.print(", Z=");
Serial.print(positionVP.z, res);
Serial.print(", Angle=");
Serial.print(positionVP.angle, res);
Serial.println();
}
// Enviar datos a la Pixhawk
sendToPixhawk();
t1 = millis();
}
}
void sendToPixhawk() {
mavlink_message_t msg;
uint8_t buffer[MAVLINK_MAX_PACKET_LEN];
// Enviar datos de posición local_position_ned
if (hedge.getPositionFromMarvelmindHedge(true, &positionVP)) {
mavlink_msg_local_position_ned_pack(1, 200, &msg, millis(), positionVP.x / 1000.0, positionVP.y / 1000.0, positionVP.z / 1000.0, 0, 0, 0);
uint16_t len = mavlink_msg_to_send_buffer(buffer, &msg);
Serial1.write(buffer, len);
}
// Enviar datos de posición vision_position_estimate
if (hedge.getPositionFromMarvelmindHedge(true, &positionVP)) {
float pos_x = positionVP.x / 1000.0;
float pos_y = positionVP.y / 1000.0;
float pos_z = positionVP.z / 1000.0;
float covariance[21] = {0}; // Inicializar el arreglo de covarianza a ceros
uint8_t reset_counter = 0; // Inicializar el contador de reinicio
mavlink_msg_vision_position_estimate_pack(1, 200, &msg, millis() * 1000, pos_x, pos_y, pos_z, 0, 0, 0, covariance, reset_counter);
uint16_t len = mavlink_msg_to_send_buffer(buffer, &msg);
Serial1.write(buffer, len);
}
}