Skip to content

Commit

Permalink
Add beginning of a unit test and fix linux compile errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
lovettchris committed Apr 7, 2017
1 parent 065bbe9 commit b489084
Show file tree
Hide file tree
Showing 18 changed files with 152 additions and 99 deletions.
4 changes: 2 additions & 2 deletions AirLib/include/controllers/rosflight/AirSimRosFlightBoard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AirSimRosFlightBoard : public rosflight::Board {

virtual uint32_t millis() override
{
return static_cast<uint64_t>(Utils::getTimeSinceEpoch() * 1E3);
return static_cast<uint32_t>(Utils::getTimeSinceEpoch() * 1E3);
}

virtual void init_sensors(uint16_t& acc1G, float& gyro_scale, int boardVersion, const std::function<void(void)>& imu_updated_callback) override
Expand Down Expand Up @@ -196,7 +196,7 @@ class AirSimRosFlightBoard : public rosflight::Board {

virtual void delay_millis(uint32_t ms) override
{
sleep(ms);
sleep(static_cast<float>(ms));
}

virtual void system_reset(bool toBootloader) override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class RosFlightDroneController : public DroneControllerBase {
return RCData();
}

void setRCData(const RCData& rcData)
void setRCData(const RCData& rcData) override
{
if (rcData.is_connected) {
board_->setInputChannel(0, angleToPwm(rcData.roll)); //X
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Estimator {
vector_t wbar;
vector_t wfinal;
vector_t w_acc;
constexpr static vector_t g = {0.0f, 0.0f, -1.0f};
const vector_t g = {0.0f, 0.0f, -1.0f}; // 'static constexpr' here results in link error.
vector_t b;
quaternion_t q_tilde;
quaternion_t q_hat;
Expand Down
14 changes: 7 additions & 7 deletions AirLib/include/controllers/rosflight/firmware/mixer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Mixer {
Params* params;
Board* board;

constexpr static mixer_t quadcopter_plus_mixing =
const mixer_t quadcopter_plus_mixing =
{
{M, M, M, M, NONE, NONE, NONE, NONE}, // output_type

Expand All @@ -79,7 +79,7 @@ class Mixer {
};


constexpr static mixer_t quadcopter_x_mixing =
const mixer_t quadcopter_x_mixing =
{
{M, M, M, M, NONE, NONE, NONE, NONE}, // output_type

Expand All @@ -89,7 +89,7 @@ class Mixer {
{-1.0f, 1.0f, 1.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f} // Z Mix
};

constexpr static mixer_t quadcopter_h_mixing =
const mixer_t quadcopter_h_mixing =
{
{M, M, M, M, NONE, NONE, NONE, NONE}, // output_type

Expand All @@ -99,7 +99,7 @@ class Mixer {
{-1.0f, 1.0f, 1.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f} // Z Mix
};

constexpr static mixer_t fixedwing_mixing =
const mixer_t fixedwing_mixing =
{
{S, S, M, S, NONE, NONE, NONE, NONE},

Expand All @@ -109,7 +109,7 @@ class Mixer {
{ 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f} // Z Mix
};

constexpr static mixer_t tricopter_mixing =
const mixer_t tricopter_mixing =
{
{M, M, M, S, NONE, NONE, NONE, NONE},

Expand All @@ -119,7 +119,7 @@ class Mixer {
{ 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f} // Z Mix
};

constexpr static mixer_t Y6_mixing =
const mixer_t Y6_mixing =
{
{M, M, M, M, M, M, NONE, NONE},
{ 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f}, // F Mix
Expand All @@ -128,7 +128,7 @@ class Mixer {
{-1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 0.0f, 0.0f} // Z Mix
};

constexpr static mixer_t const *array_of_mixers[NUM_MIXERS] =
const mixer_t *array_of_mixers[NUM_MIXERS] =
{
&quadcopter_plus_mixing,
&quadcopter_x_mixing,
Expand Down
20 changes: 10 additions & 10 deletions AirLib/include/vehicles/configs/BlacksheepQuadX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ namespace msr {

// relative to Forward vector in the order (0,3,1,2) required by quad X pattern
// http://ardupilot.org/copter/_images/MOTORS_QuadX_QuadPlus.jpg
arm_lengths.push_back(0.22);
arm_lengths.push_back(0.255);
arm_lengths.push_back(0.22);
arm_lengths.push_back(0.255);
arm_lengths.push_back(0.22f);
arm_lengths.push_back(0.255f);
arm_lengths.push_back(0.22f);
arm_lengths.push_back(0.255f);

// note: the Forward vector is actually the "x" axis, and the AngleAxisr rotation is pointing down and is left handed, so this means the rotation
// is counter clockwise, so the vector (arm_lengths[i], 0) is the X-axis, so the CCW rotations to position each arm correctly are listed below:
// See measurements here: http://diydrones.com/profiles/blogs/arducopter-tbs-discovery-style (angles reversed because we are doing CCW rotation)
std::vector<real_T> arm_angles;
arm_angles.push_back(-55);
arm_angles.push_back(125);
arm_angles.push_back(55);
arm_angles.push_back(-125);
arm_angles.push_back(-55.0f);
arm_angles.push_back(125.0f);
arm_angles.push_back(55.0f);
arm_angles.push_back(-125.0f);

// quad X pattern
std::vector<RotorTurningDirection> rotor_directions;
Expand All @@ -71,8 +71,8 @@ namespace msr {

// the props we are using a E-Prop, which I didn't find in UIUC database, but this one is close:
// http://m-selig.ae.illinois.edu/props/volume-2/plots/ef_130x70_static_ctcp.png
params.rotor_params.C_T = 0.11;
params.rotor_params.C_P = 0.047;
params.rotor_params.C_T = 0.11f;
params.rotor_params.C_P = 0.047f;
params.rotor_params.max_rpm = 9500;
params.rotor_params.calculateMaxThrust();
params.rotor_params.throttle_boost = 0;
Expand Down
2 changes: 1 addition & 1 deletion AirLib/include/vehicles/configs/FlamewheelQuadX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FlamewheelQuadX : public MultiRotorParams {
//set up arm lengths
//dimensions are for F450 frame: http://artofcircuits.com/product/quadcopter-frame-hj450-with-power-distribution
params.rotor_count = 4;
std::vector<real_T> arm_lengths(params.rotor_count, 0.225);
std::vector<real_T> arm_lengths(params.rotor_count, 0.225f);
std::vector<real_T> arm_angles(params.rotor_count, 45);

//set up mass
Expand Down
2 changes: 1 addition & 1 deletion AirLib/include/vehicles/configs/RosFlightQuadX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class RosFlightQuadX : public MultiRotorParams {
//setup rotor poses
params.rotor_poses.clear();
params.rotor_poses.emplace_back(Vector3r(0.230f, 0.1926f, -0.0762f), Vector3r(0.0223925f, -0.02674078f, -0.99939157f), RotorTurningDirection::RotorTurningDirectionCCW);
params.rotor_poses.emplace_back(Vector3r(-0.205, -0.1907f, -0.0762f), Vector3r(-0.02375588f, 0.02553726f, -0.99939157f), RotorTurningDirection::RotorTurningDirectionCCW);
params.rotor_poses.emplace_back(Vector3r(-0.205f, -0.1907f, -0.0762f), Vector3r(-0.02375588f, 0.02553726f, -0.99939157f), RotorTurningDirection::RotorTurningDirectionCCW);
params.rotor_poses.emplace_back(Vector3r(0.205f, -0.1907f, -0.0762f), Vector3r(0.02375588f, 0.02553726f, -0.99939157f), RotorTurningDirection::RotorTurningDirectionCW);
params.rotor_poses.emplace_back(Vector3r(-0.230f, 0.1926f, -0.0762f), Vector3r(-0.0223925f, -0.02674078f, -0.99939157f), RotorTurningDirection::RotorTurningDirectionCW);

Expand Down
8 changes: 6 additions & 2 deletions AirLibUnitTests/AirLibUnitTests.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// AirLibUnitTests.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <cassert>
#include "TestVehicles.hpp"

int main()
{
assert(1 + 1 > 1);
Settings& settings = Settings::loadJSonFile("settings.json");

TestVehicles test1;
test1.Run();

return 0;
}

31 changes: 18 additions & 13 deletions AirLibUnitTests/AirLibUnitTests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>../AirLib/Include;$(EIGEN_ROOT)\Eigen3;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -96,11 +97,12 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>../AirLib/Include;$(EIGEN_ROOT)\Eigen3;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -110,12 +112,13 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>../AirLib/Include;$(EIGEN_ROOT)\Eigen3;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -127,12 +130,13 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>../AirLib/Include;$(EIGEN_ROOT)\Eigen3;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -145,17 +149,18 @@
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
<ClCompile Include="AirLibUnitTests.cpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="AirLibUnitTests.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ProjectReference Include="..\AirLib\AirLib.vcxproj">
<Project>{4bfb7231-077a-4671-bd21-d3ade3ea36e7}</Project>
</ProjectReference>
<ProjectReference Include="..\MavLinkCom\MavLinkCom.vcxproj">
<Project>{8510c7a4-bf63-41d2-94f6-d8731d137a5a}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClInclude Include="TestVehicles.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
16 changes: 5 additions & 11 deletions AirLibUnitTests/AirLibUnitTests.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,13 @@
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="targetver.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="AirLibUnitTests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="TestVehicles.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
37 changes: 37 additions & 0 deletions AirLibUnitTests/TestVehicles.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

#ifndef msr_AirLibUnitTests_TestVehicles_hpp
#define msr_AirLibUnitTests_TestVehicles_hpp

#include <chrono>
#include <cassert>
#include "vehicles/configs/PX4ConfigCreator.hpp"
#include "vehicles/configs/RosFlightQuadX.hpp"

using namespace msr::airlib;

class TestVehicles
{
public:
void Run() {

// try the RosFlightQuadX.
RosFlightQuadX rosFlight;
rosFlight.initialize();

// Test PX4 based drones
std::unique_ptr<MultiRotorParams> params = PX4ConfigCreator::createConfig("Pixhawk");
params->initialize();

DroneControllerBase* controller = params->getController();
assert(controller != nullptr);

controller->start();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
controller->stop();


return;
}
};

#endif
8 changes: 0 additions & 8 deletions AirLibUnitTests/stdafx.cpp

This file was deleted.

15 changes: 0 additions & 15 deletions AirLibUnitTests/stdafx.h

This file was deleted.

8 changes: 0 additions & 8 deletions AirLibUnitTests/targetver.h

This file was deleted.

8 changes: 4 additions & 4 deletions DroneShell/DroneShell.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ProjectDir)..\AirLib\deps\rpclib\include;include;$(EIGEN_ROOT)\Eigen3;$(BOOST_ROOT);$(ProjectDir)..\AirLib\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)..\AirLib\deps\rpclib\include;include;$(EIGEN_ROOT)\Eigen3;$(ProjectDir)..\AirLib\include</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
<AdditionalOptions>/w34263 /w34266 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
Expand All @@ -114,7 +114,7 @@
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ProjectDir)..\AirLib\deps\rpclib\include;include;$(EIGEN_ROOT)\Eigen3;$(BOOST_ROOT);$(ProjectDir)..\AirLib\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)..\AirLib\deps\rpclib\include;include;$(EIGEN_ROOT)\Eigen3;$(ProjectDir)..\AirLib\include</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
<AdditionalOptions>/w34263 /w34266 %(AdditionalOptions)</AdditionalOptions>
<DisableSpecificWarnings>4100;4505;4820;4464;4514;4710;4571;%(DisableSpecificWarnings)</DisableSpecificWarnings>
Expand All @@ -135,7 +135,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ProjectDir)..\AirLib\deps\rpclib\include;include;$(EIGEN_ROOT)\Eigen3;$(BOOST_ROOT);$(ProjectDir)..\AirLib\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)..\AirLib\deps\rpclib\include;include;$(EIGEN_ROOT)\Eigen3;$(ProjectDir)..\AirLib\include</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
<AdditionalOptions>/w34263 /w34266 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
Expand All @@ -157,7 +157,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ProjectDir)..\AirLib\deps\rpclib\include;include;$(EIGEN_ROOT)\Eigen3;$(BOOST_ROOT);$(ProjectDir)..\AirLib\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)..\AirLib\deps\rpclib\include;include;$(EIGEN_ROOT)\Eigen3;$(ProjectDir)..\AirLib\include</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
<AdditionalOptions>/w34263 /w34266 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
Expand Down
Loading

0 comments on commit b489084

Please sign in to comment.