Skip to content
Permalink
bf3b31bdd5
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
77 lines (55 sloc) 1.66 KB
#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;
}