Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
77 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |