Skip to content
Permalink
82b30fbad2
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
60 lines (44 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_conversion( struct can_frame fr )
{
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();
}
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 )
{
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 );
for( int i=0; i<frame.can_dlc; ++i )
printf( " %02X", frame.data[i] );
printf("\n");
}
}
can_close( canSocket );
return 0;
}