(main.cpp)
(main.cpp)
Line 30: Line 30:
 
     pthread_create(&hThread, NULL, ioThreadProc, 0);
 
     pthread_create(&hThread, NULL, ioThreadProc, 0);
 
     printf(">CAN: starts listening CAN frames\n");
 
     printf(">CAN: starts listening CAN frames\n");
 
    //query h/w information
 
    printf(">CAN: query system information\n");
 
    ret = request_hand_information(CAN_Ch);
 
    if(ret < 0)
 
    {
 
        printf("ERROR request_hand_information !!! \n");
 
        command_can_close(CAN_Ch);
 
        return false;
 
    }
 
    ret = request_hand_serial(CAN_Ch);
 
    if(ret < 0)
 
    {
 
        printf("ERROR request_hand_serial !!! \n");
 
        command_can_close(CAN_Ch);
 
        return false;
 
    }
 
  
 
     // set periodic communication parameters(period)
 
     // set periodic communication parameters(period)

Revision as of 13:30, 2 July 2019

CAN Communication Tutorial

Please download CAN_tutorial.zip file and follow below steps. File:CAN tutorial.zip
CAN_tutorial.zip contains CMakeList.txt, README and grasp directory.

This tutorial will show how to open & close CAN communication. Also, how to get position data and send pwm to operate Allegro Hand. You will follow step by step with adding sample codes.


simple diagram

Below picture shows a structure of a sample program for this tutorial.
Tutorial .png

main.cpp

You can find main.cpp in grasp directory. There are 3 functions you have to edit.

bool OpenCAN()

    // CAN open
    int ret = command_can_open(CAN_Ch);
    if(ret < 0)
    {
        printf("ERROR command_can_open !!! \n");
        return false;
    }
 
    // initialize CAN I/O thread
    ioThreadRun = true;
    pthread_create(&hThread, NULL, ioThreadProc, 0);
    printf(">CAN: starts listening CAN frames\n");
 
    // set periodic communication parameters(period)
    printf(">CAN: Comm period set\n");
    short comm_period[3] = {3, 0, 0}; // millisecond {position, imu, temperature}
    ret = command_set_period(CAN_Ch, comm_period);
    if(ret < 0)
    {
        printf("ERROR command_set_period !!! \n");
        command_can_close(CAN_Ch);
        return false;
    }
 
    // servo on
    printf(">CAN: servo on\n");
    ret = command_servo_on(CAN_Ch);
    if(ret < 0)
    {
        printf("ERROR command_servo_on !!! \n");
        command_set_period(CAN_Ch, 0);
        command_can_close(CAN_Ch);
        return false;
    }
 
    return true;




static void* ioThreadProc(void* inst)

// --




void CloseCAN()

// --







Whos here now:   Members 0   Guests 0   Bots & Crawlers 1