Replies: 4 comments 3 replies
-
|
Beta Was this translation helpful? Give feedback.
-
Thank you. When trying to send sonar values, I cannot find the corresponding value for MSP_SET_RAW_GPS 201. 2.Use MSPv2 3.,4. I haven't caught up on those yet, but sending sensor values seems quite difficult. I will keep trying, so please let me know if you have any hints. |
Beta Was this translation helpful? Give feedback.
-
I switched to v2.
|
Beta Was this translation helpful? Give feedback.
-
The API works if you implement MSPv2 correctly, in particular the checksum (which is documented on the Wiki). |
Beta Was this translation helpful? Give feedback.
-
Hello,
I want to send sonar values to the FC using Arduino and inav MSP.
I'm considering using Arduino to send sonar values to the FC using inav MSP.
With the following sample code, I can send GPS values, but I can't send the SONAR distance.
I think that if the data is sent correctly, the values should be displayed in the sensor section of the INAV Configurator.
However, they are not being displayed, and the graph shows -1.
Could someone please advise me on how to send sonar values to the FC?
・INAV Configurator 6.1.0
・FC Fiemware 6.1.1 [KAKUTEF4V2]
#include <SoftwareSerial.h>
#include <stdlib.h>
#define MSP_SET_RAW_GPS 201 // MSP command code
#define MSP_SET_SONAR 210 // SONAR MSP command code ??
SoftwareSerial mspSerial(10, 11); // RX TX
// Define a structure for GPS data
typedef struct {
uint8_t fixType; // GPS fix type (0: invalid, 3: 3D fix)
uint8_t numSat; // Number of satellites in view
int32_t lat; // Latitude (1 / 10000000 deg)
int32_t lon; // Longitude (1 / 10000000 deg)
int16_t alt; // Altitude (meters)
int16_t groundSpeed; // Ground speed (cm/s)
} msp_set_raw_gps_t;
// Define a structure for SONAR data
typedef struct {
uint32_t sonarDist; // SONAR distance (cm)
} msp_set_sonar_t;
// Add prototype for sendMSP function
void sendMSP(uint8_t cmd, void* data, uint8_t n_bytes);
void setup() {
mspSerial.begin(115200);
Serial.begin(115200);
randomSeed(analogRead(0)); // Initialize random seed
}
void loop() {
// Dummy GPS information
uint8_t fixType = 3; // GPS fix type (0: invalid, 3: 3D fix)
uint8_t numSat = 6; // Number of satellites in view
int32_t lat = 355123; // Latitude (1 / 10000000 deg)
int32_t lon = 1391234; // Longitude (1 / 10000000 deg)
int16_t alt = 120; // Altitude (meters)
int16_t groundSpeed = 500; // Ground speed (cm/s)
}
// Function to send MSP command
void sendMSP(uint8_t cmd, void* data, uint8_t n_bytes) {
uint8_t checksum = 0;
mspSerial.write('$');
mspSerial.write('M');
mspSerial.write('<');
mspSerial.write(n_bytes);
checksum ^= n_bytes;
mspSerial.write(cmd);
checksum ^= cmd;
uint8_t* payloadPtr = (uint8_t*)data;
for (uint8_t i = 0; i < n_bytes; i++) {
uint8_t b = *(payloadPtr++);
checksum ^= b;
mspSerial.write(b);
}
mspSerial.write(checksum);
}
Beta Was this translation helpful? Give feedback.
All reactions