当前位置: 首页>>代码示例>>C++>>正文


C++ Port::ClearPort方法代码示例

本文整理汇总了C++中Port::ClearPort方法的典型用法代码示例。如果您正苦于以下问题:C++ Port::ClearPort方法的具体用法?C++ Port::ClearPort怎么用?C++ Port::ClearPort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Port的用法示例。


在下文中一共展示了Port::ClearPort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char** argv){
    Port* port = new Port("/dev/ttyUSB0");
    if(port->OpenPort() == false){
        fprintf(stderr, "\n Fail to open port\n");
        fprintf(stderr, " CM-730 is used by another program or do not have root privileges.\n\n");
        return 0;
    }

    //dxl power on stuff
    //(WriteByte(CM730::ID_CM, CM730::P_DXL_POWER, 1, 0)

    unsigned char dxltxpacket[] = {0xFF, 0xFF, 0xC8, 0x04, 0x03, 0x18, 0x01, 0};
    dxltxpacket[7] = CalculateChecksum(dxltxpacket);
    port->WritePort(dxltxpacket, 8);
    usleep(2000);

    printf("Finshed dxl power up. Press enter\n");
    getchar();

    Init_to_Pose(port);
    getchar();   
  
    unsigned char packet[100] = {0, };
    usleep(2000);
    unsigned char dip_params[3] = {DGAIN, IGAIN, PGAIN};
    MakePacket(packet, 0x05, 3, 0x03, 0x1A, dip_params);
    port->ClearPort();
    port->WritePort(packet, 10);
    usleep(2000);

    int gainread = 0;
    gainread = ReadWord(port, 0x05, 0x1B);
    int iread = GetLowByte(gainread);
    int pread = GetHighByte(gainread);
    printf("i gain: %d\n", iread);
    printf("p gain: %d\n", pread);

if(EYES){
    int color = MakeColor(230, 0, 230);
    
    // LED packet
    packet[0] = 0xFF;
    packet[1] = 0xFF;
    packet[2] = 0xC8;
    packet[3] = 0x05;
    packet[4] = 0x03;
    packet[5] = 0x1A;
    packet[6] = GetLowByte(color);
    packet[7] = GetHighByte(color);
    packet[8] = CalculateChecksum(packet); 

    port->ClearPort();
    port->WritePort(packet, 9);
    usleep(2000);
   
    packet[5] = 0x1C;
    packet[8] = CalculateChecksum(packet);
    port->ClearPort();
    port->WritePort(packet, 9);
    usleep(2000);

    getchar();

    // 0x01C for eye LEDs, 0x1A for head LED
    unsigned char txpacket[] = {0xFF, 0xFF, 0xC8, 0x05, 0x03, 0x1C, 0xE0, 0x03, 0};
    txpacket[8] = CalculateChecksum(txpacket);
    printf("%d \n", txpacket[8]);

    int value = port->WritePort(txpacket, 9);


    printf("press enter\n");
    getchar();

    double r[total] = {0, };
    double g[total] = {0, };
    double b[total] = {0, };

    int count;

    for(count = 0; count < total; count++){
        r[count] = 255*sin(6.28*count/(total/2));
        g[count] = 255*sin(6.28*count/(total/11));
        b[count] = 255*sin(6.28*count/(total/21));
    }

    count = 0;
    int newcolor;

    while(count < total){
        port->ClearPort();
        newcolor = MakeColor(r[count], g[count], b[count]);
        txpacket[6] = GetLowByte(newcolor);
        txpacket[7] = GetHighByte(newcolor);
        txpacket[8] = 0;
        txpacket[8] = CalculateChecksum(txpacket);
        port->WritePort(txpacket, 9);
        usleep(10000);
        count++;
    } 
//.........这里部分代码省略.........
开发者ID:amy-s-han,项目名称:darwin-updates,代码行数:101,代码来源:demo.cpp


注:本文中的Port::ClearPort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。