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
2023 competition changes
- Loading branch information
David
committed
Sep 20, 2023
1 parent
a45a2bd
commit a7a6fb2
Showing
9 changed files
with
230 additions
and
87 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,54 @@ | ||
#include "include/can_wrap.hpp" | ||
#include "include/candata.h" | ||
|
||
#include <iomanip> | ||
|
||
int main() | ||
{ | ||
float f = 0.0E-1f; | ||
|
||
std::cout << std::fixed << f << "\n"; | ||
|
||
return 0; | ||
|
||
const std::string device = "vcan0"; | ||
const int canSocket = can::connect( device ); | ||
|
||
while( true ) | ||
{ | ||
try | ||
{ | ||
const can_frame frame = can::read( canSocket ); | ||
|
||
if( frame.can_id == CANDATA_VCU2_AI_STATUS_FRAME_ID ) | ||
{ | ||
candata_vcu2_ai_status_t data; | ||
candata_vcu2_ai_status_unpack( &data, frame.data, frame.can_dlc ); | ||
std::cout << "status: " << | ||
candata_vcu2_ai_status_as_state_decode( data.as_state ) << "\n"; | ||
} | ||
else if( frame.can_id == CANDATA_VCU2_AI_BRAKE_FRAME_ID ) | ||
{ | ||
candata_vcu2_ai_brake_t data; | ||
candata_vcu2_ai_brake_unpack( &data, frame.data, frame.can_dlc ); | ||
std::cout << "brake: " << std::fixed << std::setprecision( 10 ) << | ||
candata_vcu2_ai_brake_hyd_press_f_pct_decode( data.hyd_press_f_pct ) << " " << | ||
candata_vcu2_ai_brake_hyd_press_r_pct_decode( data.hyd_press_r_pct ) << "\n"; | ||
} | ||
else if( frame.can_id == CANDATA_VCU2_AI_DRIVE_F_FRAME_ID ) | ||
{ | ||
candata_vcu2_ai_drive_f_t data; | ||
candata_vcu2_ai_drive_f_unpack( &data, frame.data, frame.can_dlc ); | ||
std::cout << "axle: " << | ||
candata_vcu2_ai_drive_f_front_axle_trq_decode( data.front_axle_trq ) << "\n"; | ||
} | ||
// std::cout << "status frame" << "\n"; | ||
} | ||
catch( const can::error& ) | ||
{ | ||
// no more frames to read | ||
} | ||
} | ||
|
||
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
Empty file.
Empty file.
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,114 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
#include <fcntl.h> | ||
|
||
#include <iomanip> | ||
#include <iostream> | ||
#include <map> | ||
#include <string> | ||
#include <thread> | ||
|
||
#include "simple_adas.hpp" | ||
|
||
int main( int argc, char* argv[] ) | ||
{ | ||
adas_api::SimpleAdas adas { argc >= 2 ? argv[1] : "can0" }; // was "vcan0" | ||
|
||
bool running = true; | ||
std::mutex adasMutex; | ||
std::thread processThread( [&]() | ||
{ | ||
while( running ) | ||
{ | ||
adasMutex.lock(); | ||
adas.read(); | ||
adas.write(); | ||
adasMutex.unlock(); | ||
std::this_thread::sleep_for( std::chrono::milliseconds(5) ); | ||
} | ||
} ); | ||
|
||
enum States | ||
{ | ||
IDLE, | ||
START, | ||
LEFT, | ||
RIGHT, | ||
CENTER, | ||
INCREMENT, | ||
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; | ||
|
||
if( !adas.go() ) state = IDLE; | ||
|
||
switch( state ) | ||
{ | ||
case IDLE: | ||
if( adas.go() ) | ||
state = START; | ||
break; | ||
|
||
case START: | ||
adas.set_rpm( 100 ); | ||
adas.set_brakes( 0 ); | ||
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 = INCREMENT; | ||
adas.set_angle( 0.f ); | ||
break; | ||
|
||
case INCREMENT: | ||
count += 1; | ||
if( count < 20 ) | ||
state = IDLE; | ||
else | ||
state = DONE; | ||
break; | ||
|
||
case DONE: | ||
adas.finish(); | ||
break; | ||
} | ||
|
||
if( state != prev ) | ||
timer = clock::now(); | ||
|
||
adas.read(); | ||
adas.write(); | ||
|
||
std::this_thread::sleep_for( std::chrono::milliseconds(10) ); | ||
} | ||
|
||
running = false; | ||
processThread.join(); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.