Skip to content

Commit

Permalink
Merge pull request #3156 from microsoft/clovett/pixhawk4_autodetect
Browse files Browse the repository at this point in the history
fix auto-detect of pixhawk 4 hardware
  • Loading branch information
lovettchris authored Nov 20, 2020
2 parents e1de671 + 3184ccf commit a511525
Show file tree
Hide file tree
Showing 14 changed files with 3,688 additions and 1,022 deletions.
4 changes: 2 additions & 2 deletions AirLib/include/vehicles/multirotor/RotorParams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ namespace msr {
max_speed_square = pow(max_speed, 2.0f);

real_T nsquared = revolutions_per_second * revolutions_per_second;
max_thrust = C_T * air_density * nsquared * pow(propeller_diameter, 4);
max_torque = C_P * air_density * nsquared * pow(propeller_diameter, 5) / (2 * M_PIf);
max_thrust = static_cast<real_T>(C_T * air_density * nsquared * pow(propeller_diameter, 4));
max_torque = static_cast<real_T>(C_P * air_density * nsquared * pow(propeller_diameter, 5) / (2 * M_PI));
}

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ class MavLinkMultirotorApi : public MultirotorApiBase
mavlinkcom::SerialPortInfo info = *iter;
if ((
(info.vid == pixhawkVendorId) &&
(info.pid == pixhawkFMUV4ProductId || info.pid == pixhawkFMUV2ProductId || info.pid == pixhawkFMUV2OldBootloaderProductId)
(info.pid == pixhawkFMUV4ProductId || info.pid == pixhawkFMUV2ProductId || info.pid == pixhawkFMUV2OldBootloaderProductId || info.pid == pixhawkFMUV5ProductId)
) ||
(
(info.displayName.find(L"PX4_") != std::string::npos)
Expand Down Expand Up @@ -1514,6 +1514,7 @@ class MavLinkMultirotorApi : public MultirotorApiBase
static const int pixhawkVendorId = 9900; ///< Vendor ID for Pixhawk board (V2 and V1) and PX4 Flow
static const int pixhawkFMUV4ProductId = 18; ///< Product ID for Pixhawk V2 board
static const int pixhawkFMUV2ProductId = 17; ///< Product ID for Pixhawk V2 board
static const int pixhawkFMUV5ProductId = 50; ///< Product ID for Pixhawk V5 board
static const int pixhawkFMUV2OldBootloaderProductId = 22; ///< Product ID for Bootloader on older Pixhawk V2 boards
static const int pixhawkFMUV1ProductId = 16; ///< Product ID for PX4 FMU V1 board
static const int messageReceivedTimeout = 10; ///< Seconds
Expand Down
78 changes: 44 additions & 34 deletions MavLinkCom/MavLinkComGenerator/MavLinkGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,25 @@ private void GenerateCommands()
foreach (var p in cmd.parameters)
{
string fieldName = p.label;
if (string.IsNullOrWhiteSpace(fieldName))
if (!p.reserved)
{
fieldName = NameFromDescription(p.description);
}
else
{
fieldName = LegalizeIdentifier(fieldName);
}
if (fieldName != "Empty" && fieldName != "Reserved")
{
if (!string.IsNullOrWhiteSpace(p.description))
if (string.IsNullOrWhiteSpace(fieldName) && !string.IsNullOrWhiteSpace(p.description))
{
WriteComment(" ", p.description);
fieldName = NameFromDescription(p.description);
}
else
{
fieldName = LegalizeIdentifier(fieldName);
}

if (fieldName != "Empty" && fieldName != "Reserved")
{
if (!string.IsNullOrWhiteSpace(p.description))
{
WriteComment(" ", p.description);
}
header.WriteLine(" float {0} = 0;", unique.Add(fieldName));
}
header.WriteLine(" float {0} = 0;", unique.Add(fieldName));
}
}

Expand All @@ -109,18 +113,21 @@ private void GenerateCommands()
foreach (var p in cmd.parameters)
{
i++;
string fieldName = p.label;
if (string.IsNullOrWhiteSpace(fieldName))
{
fieldName = NameFromDescription(p.description);
}
else
if (!p.reserved)
{
fieldName = LegalizeIdentifier(fieldName);
}
if (fieldName != "Empty" && fieldName != "Reserved")
{
impl.WriteLine(" param{0} = {1};", i, unique.Add(fieldName));
string fieldName = p.label;
if (string.IsNullOrWhiteSpace(fieldName) && !string.IsNullOrWhiteSpace(p.description))
{
fieldName = NameFromDescription(p.description);
}
else
{
fieldName = LegalizeIdentifier(fieldName);
}
if (fieldName != "Empty" && fieldName != "Reserved")
{
impl.WriteLine(" param{0} = {1};", i, unique.Add(fieldName));
}
}
}
impl.WriteLine("}");
Expand All @@ -133,18 +140,21 @@ private void GenerateCommands()
foreach (var p in cmd.parameters)
{
i++;
string fieldName = p.label;
if (string.IsNullOrWhiteSpace(fieldName))
{
fieldName = NameFromDescription(p.description);
}
else
if (!p.reserved)
{
fieldName = LegalizeIdentifier(fieldName);
}
if (fieldName != "Empty" && fieldName != "Reserved")
{
impl.WriteLine(" {1} = param{0};", i, unique.Add(fieldName));
string fieldName = p.label;
if (string.IsNullOrWhiteSpace(fieldName) && !string.IsNullOrWhiteSpace(p.description))
{
fieldName = NameFromDescription(p.description);
}
else
{
fieldName = LegalizeIdentifier(fieldName);
}
if (fieldName != "Empty" && fieldName != "Reserved")
{
impl.WriteLine(" {1} = param{0};", i, unique.Add(fieldName));
}
}
}
impl.WriteLine("}");
Expand Down
5 changes: 5 additions & 0 deletions MavLinkCom/MavLinkComGenerator/MavLinkMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public class MavParam
[XmlAttribute]
public string label { get; set; }

[XmlAttribute]
public bool reserved { get; set; }

[XmlAttribute]
public string @default { get; set; }
}

public class MavEnumEntry
Expand Down
3 changes: 2 additions & 1 deletion MavLinkCom/MavLinkTest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ using namespace std::filesystem;
static const int pixhawkVendorId = 9900; ///< Vendor ID for Pixhawk board (V2 and V1) and PX4 Flow
static const int pixhawkFMUV4ProductId = 18; ///< Product ID for Pixhawk V2 board
static const int pixhawkFMUV2ProductId = 17; ///< Product ID for Pixhawk V2 board
static const int pixhawkFMUV5ProductId = 50; ///< Product ID for Pixhawk V5 board
static const int pixhawkFMUV2OldBootloaderProductId = 22; ///< Product ID for Bootloader on older Pixhawk V2 boards
//static const int pixhawkFMUV1ProductId = 16; ///< Product ID for PX4 FMU V1 board

Expand Down Expand Up @@ -1015,7 +1016,7 @@ std::string findPixhawk() {
{
SerialPortInfo info = *iter;
if (info.vid == pixhawkVendorId) {
if (info.pid == pixhawkFMUV4ProductId || info.pid == pixhawkFMUV2ProductId || info.pid == pixhawkFMUV2OldBootloaderProductId)
if (info.pid == pixhawkFMUV4ProductId || info.pid == pixhawkFMUV2ProductId || info.pid == pixhawkFMUV2OldBootloaderProductId || info.pid == pixhawkFMUV5ProductId)
{
printf("Auto Selecting COM port: %S\n", info.displayName.c_str());

Expand Down
Loading

0 comments on commit a511525

Please sign in to comment.