Skip to content
Permalink
Browse files
Fixed WheelSpeedsFrame/WheelRpmsFrame naming issue
  • Loading branch information
David committed Jan 20, 2023
1 parent 191052b commit 5d5afefb2edf70512626602d02dda6155c7f6f5c
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 159 deletions.
@@ -34,7 +34,7 @@ SET( LIBRARY_OUTPUT_PATH lib )
# autogenerate code from the DBC file
file( MAKE_DIRECTORY src_autogen )
add_custom_command( OUTPUT src_autogen/candata.h src_autogen/candata.c
COMMAND python3 -m cantools generate_c_source docs/candata.dbc -o src_autogen
COMMAND python3 -m cantools generate_c_source ${CMAKE_CURRENT_SOURCE_DIR}/docs/candata.dbc -o src_autogen
MAIN_DEPENDENCY docs/candata.dbc
COMMENT "Autogenerate code from DBC file" )

@@ -71,18 +71,18 @@ target_include_directories( wheel_counts_frame PUBLIC include )
target_link_libraries( wheel_counts_frame PRIVATE candata )
target_link_libraries( wheel_counts_frame PUBLIC process_frame )

add_library( wheel_rpms_frame SHARED src/status/wheel_rpms_frame.cpp )
target_include_directories( wheel_rpms_frame PUBLIC include )
target_link_libraries( wheel_rpms_frame PRIVATE candata )
target_link_libraries( wheel_rpms_frame PUBLIC process_frame )
add_library( wheel_speeds_frame SHARED src/status/wheel_speeds_frame.cpp )
target_include_directories( wheel_speeds_frame PUBLIC include )
target_link_libraries( wheel_speeds_frame PRIVATE candata )
target_link_libraries( wheel_speeds_frame PUBLIC process_frame )

add_library( status_frames SHARED src/status_frames.cpp )
target_include_directories( status_frames PUBLIC include )
target_link_libraries( status_frames PUBLIC axle_torque_frame
status_frame
steering_frame
wheel_counts_frame
wheel_rpms_frame )
wheel_speeds_frame )

# output frames
add_library( control_frame SHARED src/control/control_frame.cpp )
@@ -17,9 +17,9 @@ public:
bool is_front() const;

AxleControlFrame( const AxleTorqueFrame &torqueFrame,
const WheelRpmsFrame &rpmsFrame,
const WheelSpeedsFrame &speedsFrame,
const bool front=true );
~AxleControlFrame();
virtual ~AxleControlFrame() = default;

void set_speed( const float speed );

@@ -41,7 +41,7 @@ private:
virtual void _print( std::ostream& os ) const override;

const AxleTorqueFrame& _torqueFrame;
const WheelRpmsFrame& _rpmsFrame;
const WheelSpeedsFrame& _speedsFrame;

const bool _front;
float _speed = 0.f;
@@ -80,8 +80,8 @@ can_frame AxleControlFrame::_process() const
torque = this->_torqueFrame.get_max();
}

if( this->_rpmsFrame.is_recent() )
torque = torque_rpm_limit( torque, this->_rpmsFrame.fastest() );
if( this->_speedsFrame.is_recent() )
torque = torque_rpm_limit( torque, this->_speedsFrame.fastest() );

can_frame frame;
frame.can_id = this->frameId;
@@ -120,18 +120,13 @@ void AxleControlFrame::_print( std::ostream& os ) const
}

AxleControlFrame::AxleControlFrame( const AxleTorqueFrame &torqueFrame,
const WheelRpmsFrame &rpmsFrame,
const WheelSpeedsFrame &speedsFrame,
const bool front ) :
ControlFrame( front ? CANDATA_AI2_VCU_DRIVE_F_FRAME_ID : CANDATA_AI2_VCU_DRIVE_R_FRAME_ID ),
_torqueFrame( torqueFrame ),
_rpmsFrame( rpmsFrame ),
_speedsFrame( speedsFrame ),
_front( front )
{
}

AxleControlFrame::~AxleControlFrame()
{
}


#endif // AXLE_CONTROL_FRAME_H

This file was deleted.

@@ -11,16 +11,17 @@
class WheelSpeedsFrame : public ProcessFrame
{
public:
using counts_t = int;
using rpm_t = int;

const counts_t count( size_t index ) const;
const counts_t front_left() const;
const counts_t front_right() const;
const counts_t rear_left() const;
const counts_t rear_right() const;
const rpm_t rpm( size_t index ) const;
const rpm_t front_left() const;
const rpm_t front_right() const;
const rpm_t rear_left() const;
const rpm_t rear_right() const;
const rpm_t fastest() const;

WheelSpeedsFrame();
~WheelSpeedsFrame();
virtual ~WheelSpeedsFrame() = default;

private:
virtual void _process( const can_frame& frame ) override;
@@ -3,5 +3,4 @@
#include "status/status_frame.h"
#include "status/steering_frame.h"
#include "status/wheel_counts_frame.h"
#include "status/wheel_rpms_frame.h"
#include "status/wheel_speeds_frame.h"
@@ -14,7 +14,7 @@ using can::operator<<;

#include <status_frames.h>

ftxui::Component Wrap( std::string name, Component component )
ftxui::Component Wrap( const std::string& name, Component component )
{
return Renderer(component, [name, component] {
return hbox({
@@ -42,9 +42,9 @@ public:
StatusFrame status;
SteeringFrame steering;
WheelCountsFrame wheelCounts;
WheelRpmsFrame wheelRpms;
WheelSpeedsFrame wheelSpeeds;

std::array< ProcessFrame* const, 6 > frames { &frontAxle, &rearAxle, &status, &steering, &wheelCounts, &wheelRpms };
std::array< ProcessFrame* const, 6 > frames { &frontAxle, &rearAxle, &status, &steering, &wheelCounts, &wheelSpeeds };

int canSocket;

@@ -165,7 +165,7 @@ public:
} ) | border;
};

auto axle = [&]( int current, int max, int requested )
auto axle = [&]( float current, float max, float requested )
{
return vbox(
{
@@ -189,10 +189,10 @@ public:
{
{
wheel( interface.wheelCounts.front_left(),
interface.wheelRpms.front_left() ),
interface.wheelSpeeds.front_left() ),
vcenter( hcenter( text("Front") ) ),
wheel( interface.wheelCounts.front_right(),
interface.wheelRpms.front_right() ),
interface.wheelSpeeds.front_right() ),
},
{
text(""),
@@ -214,13 +214,13 @@ public:
interface.rearAxle.get_max(),
interface.rearAxle.get_requested() ),
text(""),
},
},
{
wheel( interface.wheelCounts.rear_left(),
interface.wheelRpms.rear_left() ),
interface.wheelSpeeds.rear_left() ),
vcenter( hcenter( text("Rear") ) ),
wheel( interface.wheelCounts.rear_right(),
interface.wheelRpms.rear_right() ),
interface.wheelSpeeds.rear_right() ),
},
} );
} );
@@ -22,14 +22,14 @@ int main( int argc, char* argv[] )
StatusFrame status;
SteeringFrame steering;
WheelCountsFrame wheelCounts;
WheelRpmsFrame wheelRpms;
WheelSpeedsFrame wheelSpeeds;

AxleControlFrame frontControl( frontAxle, wheelRpms );
AxleControlFrame rearControl( rearAxle, wheelRpms, false );
AxleControlFrame frontControl( frontAxle, wheelSpeeds );
AxleControlFrame rearControl( rearAxle, wheelSpeeds, false );
StatusControlFrame statusControl( status );
SteeringControlFrame steeringControl( steering );

std::array< ProcessFrame* const, 6 > frames { &frontAxle, &rearAxle, &status, &steering, &wheelCounts, &wheelRpms };
std::array< ProcessFrame* const, 6 > frames { &frontAxle, &rearAxle, &status, &steering, &wheelCounts, &wheelSpeeds };
std::array< ControlFrame* const, 4 > controls { &frontControl, &rearControl, &statusControl, &steeringControl };

try
@@ -21,9 +21,9 @@ int main( int argc, char* argv[] )
StatusFrame status;
SteeringFrame steering;
WheelCountsFrame wheelCounts;
WheelRpmsFrame wheelRpms;
WheelSpeedsFrame wheelSpeeds;

std::array< ProcessFrame* const, 6 > frames { &frontAxle, &rearAxle, &status, &steering, &wheelCounts, &wheelRpms };
std::array< ProcessFrame* const, 6 > frames { &frontAxle, &rearAxle, &status, &steering, &wheelCounts, &wheelSpeeds };

try
{

This file was deleted.

@@ -1,7 +1,7 @@
#include "wheel_speeds_frame.h"
#include "status/wheel_speeds_frame.h"


const WheelSpeedsFrame::counts_t WheelSpeedsFrame::count( size_t index ) const
const WheelSpeedsFrame::rpm_t WheelSpeedsFrame::rpm( size_t index ) const
{
switch( index )
{
@@ -18,26 +18,32 @@ const WheelSpeedsFrame::counts_t WheelSpeedsFrame::count( size_t index ) const
return 0;
}

const WheelSpeedsFrame::counts_t WheelSpeedsFrame::front_left() const
const WheelSpeedsFrame::rpm_t WheelSpeedsFrame::front_left() const
{
return candata_vcu2_ai_speeds_fl_wheel_speed_decode( data.fl_wheel_speed );
}

const WheelSpeedsFrame::counts_t WheelSpeedsFrame::front_right() const
const WheelSpeedsFrame::rpm_t WheelSpeedsFrame::front_right() const
{
return candata_vcu2_ai_speeds_fr_wheel_speed_decode( data.fr_wheel_speed );
}

const WheelSpeedsFrame::counts_t WheelSpeedsFrame::rear_left() const
const WheelSpeedsFrame::rpm_t WheelSpeedsFrame::rear_left() const
{
return candata_vcu2_ai_speeds_rl_wheel_speed_decode( data.rl_wheel_speed );
}

const WheelSpeedsFrame::counts_t WheelSpeedsFrame::rear_right() const
const WheelSpeedsFrame::rpm_t WheelSpeedsFrame::rear_right() const
{
return candata_vcu2_ai_speeds_rr_wheel_speed_decode( data.rr_wheel_speed );
}

const WheelSpeedsFrame::rpm_t WheelSpeedsFrame::fastest() const
{
return std::max( std::max( front_left(), front_right() ),
std::max( rear_left(), rear_right() ) );
}

void WheelSpeedsFrame::_process( const can_frame& frame )
{
if( candata_vcu2_ai_speeds_unpack( &data, frame.data, frame.can_dlc ) )
@@ -48,16 +54,12 @@ void WheelSpeedsFrame::_process( const can_frame& frame )

void WheelSpeedsFrame::_print( std::ostream& os ) const
{
os << "Wheel counts: " << count(0);
os << "Wheel counts: " << rpm(0);
for( size_t i=1; i<4; ++i )
os << ", " << count(i);
os << ", " << rpm(i);
}

WheelSpeedsFrame::WheelSpeedsFrame() :
ProcessFrame( CANDATA_VCU2_AI_SPEEDS_FRAME_ID )
{
}

WheelSpeedsFrame::~WheelSpeedsFrame()
{
}

0 comments on commit 5d5afef

Please sign in to comment.