Skip to content
Permalink
Browse files
Update Race_Car.c
  • Loading branch information
adakes committed Jan 6, 2023
1 parent bf3b31b commit 82b30fbad2828443edca4d798628f0fac5f9ee46
Showing 1 changed file with 14 additions and 31 deletions.
@@ -8,60 +8,43 @@

#include "can_wrap.h"

void torque_req_calc( const int canSoc, struct can_frame fr )
void torque_conversion( struct can_frame fr )
{

}

void torque_conversion( const int canSoc, struct can_frame fr )
{

const uint16_t wheel_rpm = fr.data[3];
const uint16_t voltage = fr.data[4];
const uint16_t torque_req = fr.data[5];
const float motor_torque_current = 0.879;
const float b_electromagnetic_factor = 0.6721;
const uint16_t wheel_rpm = fr.data[3]; //Wheel RPM to receive from motor
const uint16_t voltage = fr.data[4]; //Voltage values to receive from motor
const uint16_t torque_req = fr.data[5]; //torque request received from CAN status frame
const float motor_torque_current = 0.879; //Hardcoded value for motor torque current
const float b_electromagnetic_factor = 0.6721; //EM factor
const float output_current;


/* Formula to calculate current in mA required for given torque request */
output_current = torque_req((b_electromagnetic_factor*wheel_rpm*torque_req) +
((motor_torque_current*motor_torque_current)*torque_req) +
(100))/(100*voltage)

printf();

switch( fr.can_id )
{
case 0x188:
indicator_frame( fr );
break;
case 0x244:
speed_frame( fr );
break;
default:
/* unknown frame */
break;
}
}

int main( int argc, char* argv[] )
{
/*virtual CAN device as vcan0*/
const char* canChannel = "vcan0";
/*canSocket data is received from can_wrap.h file*/
const int canSocket = can_connect( canChannel, false );

struct can_frame frame;

for( int c=0; c<100; ++c )
{

//memset( &frame, 0, sizeof(frame) );

const can_frame frame = can_read();

torque_conversion(canSocket,frame);


const can_frame frame = can_read(canSocket);

torque_conversion(frame);

/*Read CAN socket data and print id and dlc values*/
if( can_read( canSocket, &frame ) )
{
printf("0x%X [%X]", frame.can_id, frame.can_dlc );
@@ -74,4 +57,4 @@ int main( int argc, char* argv[] )
can_close( canSocket );

return 0;
}
}

0 comments on commit 82b30fb

Please sign in to comment.