Skip to content
Permalink
Browse files
Add files via upload
  • Loading branch information
adakes committed Jan 6, 2023
1 parent 29176cb commit bf3b31bdd52b84a807a739be65d92b35c112fe19
Showing 1 changed file with 77 additions and 0 deletions.
@@ -0,0 +1,77 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <linux/can.h>
#include <linux/can/raw.h>

#include "can_wrap.h"

void torque_req_calc( const int canSoc, 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 float output_current;


output_current = torque_req((b_electromagnetic_factor*wheel_rpm*torque_req) +
((motor_torque_current*motor_torque_current)*torque_req) +
(100))/(100*voltage)


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[] )
{
const char* canChannel = "vcan0";
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);




if( can_read( canSocket, &frame ) )
{
printf("0x%X [%X]", frame.can_id, frame.can_dlc );
for( int i=0; i<frame.can_dlc; ++i )
printf( " %02X", frame.data[i] );
printf("\n");
}
}

can_close( canSocket );

return 0;
}

0 comments on commit bf3b31b

Please sign in to comment.