Skip to content

Commit d4e938f

Browse files
committed
Added a test for the hardware conversions
1 parent 9388578 commit d4e938f

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/catheter_arduino_gui/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ target_link_libraries(
176176
pthread
177177
)
178178

179+
catkin_add_gtest(test_adc_dac test/test_adc_dac.cpp WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
180+
target_link_libraries(
181+
test_adc_dac
182+
catheter_analog_digital_libs
183+
${GTEST_LIBRARIES}
184+
pthread
185+
)
179186

180187
endif()
181188

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
Copyright 2017 Russell Jackson
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#include <iostream>
18+
#include <string>
19+
#include <vector>
20+
#include <gtest/gtest.h>
21+
#include "hardware/digital_analog_conversions.h"
22+
23+
24+
TEST(ard_hardware_conv, ADC_DAC)
25+
{
26+
// for each potential value of current, validate that the ADC then back to DAC is valid.
27+
for (uint16_t index(0); index < 4096; index++)
28+
{
29+
double amperageVal(adc2MilliAmp(index));
30+
uint16_t index_(milliAmp2Dac(amperageVal));
31+
ASSERT_EQ(index, index_);
32+
}
33+
}
34+
35+
TEST(ard_hardware_conv, DAC_ADC)
36+
{
37+
// for each potential value of current, validate that the ADC then back to DAC is valid.
38+
double di(0.000001);
39+
for (double i(0.0); i < 300.0; i+=di)
40+
{
41+
uint16_t dacVal(milliAmp2Dac(i));
42+
double i_(adc2MilliAmp(dacVal));
43+
double e_(abs(i-i_));
44+
ASSERT_LT(e_, 1/12.8);
45+
}
46+
}
47+
48+
49+
50+
int main(int argc, char** argv)
51+
{
52+
testing::InitGoogleTest(&argc, argv);
53+
return RUN_ALL_TESTS();
54+
}

0 commit comments

Comments
 (0)