Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added steering calibration functionality
- Loading branch information
David
committed
Feb 24, 2023
1 parent
9d174c0
commit fc28a91
Showing
11 changed files
with
194 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.0364 0.0064 0.0002 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.9475 -0.0039 -0.00006 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef CALIBRATION_HPP | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
#include <vector> | ||
#include <algorithm> | ||
#include <iterator> | ||
#include <sstream> | ||
#include <cmath> | ||
|
||
std::vector<float> read_file( std::ifstream &file ) | ||
{ | ||
std::vector<float> data; | ||
|
||
std::copy( std::istream_iterator<float>(file), | ||
std::istream_iterator<float>(), | ||
std::back_inserter(data) ); | ||
|
||
return data; | ||
} | ||
|
||
|
||
float calibration( const std::vector<float> &calib, const float input ) | ||
{ | ||
float output = 0.0f; | ||
for( size_t i=0; i<calib.size(); ++i ) | ||
output += calib[i] * powf( input, i ); | ||
return output; | ||
} | ||
|
||
#endif // CALIBRATION_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <thread> | ||
#include <vector> | ||
#include <sstream> | ||
#include <algorithm> | ||
#include <iterator> | ||
#include <fstream> | ||
|
||
#include "simple_adas.hpp" | ||
|
||
std::vector<float> read_calibration_file( const std::string filename ) | ||
{ | ||
std::ifstream file( filename ); | ||
if( !file.good() ) | ||
throw std::runtime_error( "Failed to open file: " + filename ); | ||
|
||
std::vector<float> data; | ||
|
||
std::copy( std::istream_iterator<float>(file), | ||
std::istream_iterator<float>(), | ||
std::back_inserter(data) ); | ||
|
||
return data; | ||
} | ||
|
||
int main( int argc, char* argv[] ) | ||
{ | ||
adas_api::SimpleAdas adas { argc >= 2 ? argv[1] : "can0" }; | ||
|
||
auto steeringRequestCalib = read_calibration_file( "docs/steering_request.txt" ); | ||
auto steeringFeedbackCalib = read_calibration_file( "docs/steering_feedback.txt" ); | ||
|
||
adas.set_steering_request_calibration( steeringRequestCalib ); | ||
adas.set_steering_feedback_calibration( steeringFeedbackCalib ); | ||
|
||
enum States | ||
{ | ||
IDLE, | ||
LEFT, | ||
RIGHT, | ||
CENTER, | ||
DONE | ||
} state = IDLE; | ||
|
||
using clock = std::chrono::steady_clock; | ||
clock::time_point timer; | ||
|
||
const auto timeout = std::chrono::seconds( 3 ); | ||
|
||
int count = 0; | ||
|
||
while( true ) | ||
{ | ||
States prev = state; | ||
|
||
adas.read(); | ||
|
||
if( adas.go() ) | ||
{ | ||
switch( state ) | ||
{ | ||
case IDLE: | ||
state = LEFT; | ||
break; | ||
|
||
case LEFT: | ||
if( clock::now() - timer >= timeout ) | ||
state = RIGHT; | ||
adas.set_angle( 20.f ); | ||
break; | ||
|
||
case RIGHT: | ||
if( clock::now() - timer >= timeout ) | ||
state = CENTER; | ||
adas.set_angle( -20.f ); | ||
break; | ||
|
||
case CENTER: | ||
if( clock::now() - timer >= timeout ) | ||
state = DONE; | ||
adas.set_angle( 0.f ); | ||
break; | ||
|
||
case DONE: | ||
adas.finish(); | ||
break; | ||
} | ||
} | ||
else | ||
state = IDLE; | ||
|
||
if( state != prev ) | ||
timer = clock::now(); | ||
|
||
|
||
adas.write(); | ||
|
||
std::this_thread::sleep_for( std::chrono::milliseconds(10) ); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters