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


C++ Dynamixel::Connect方法代码示例

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


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

示例1: main

int main()
{
    
    int i;

    Dynamixel DXL("/dev/ttyUSB0");
    //BulkRead bulkread(&DXL);


    // Open device
    if( DXL.Connect() == 0 )
    {
        printf( "Failed to open USB2Dynamixel!\n" );
        return 0;
    }
    else
        printf( "Succeed to open USB2Dynamixel!\n" );

	//Close port of USB2DXL
    DXL.Disconnect();
   

    return 0;
}
开发者ID:thedancomplex,项目名称:XM-430-example,代码行数:24,代码来源:main.cpp

示例2: main

int main(int argc, char *argv[])
{
    fprintf(stderr, "\n***********************************************************************\n");
    fprintf(stderr,   "*                     DXL Protocol 2.0 Monitor                        *\n");
    fprintf(stderr,   "***********************************************************************\n\n");

    char *dev = (char*)"/dev/ttyUSB0";

    /* parameter parsing */
    while(1)
    {
    	int option_index = 0, c = 0;
    	static struct option long_options[] = {
                {"h", no_argument, 0, 0},
                {"help", no_argument, 0, 0},
                {"d", required_argument, 0, 0},
                {"device", required_argument, 0, 0},
                {0, 0, 0, 0}
    	};

        /* parsing all parameters according to the list above is sufficent */
        c = getopt_long_only(argc, argv, "", long_options, &option_index);

        /* no more options to parse */
        if(c == -1) break;

        /* unrecognized option */
        if(c == '?') {
        	Usage(argv[0]);
            return 0;
        }

        /* dispatch the given options */
        switch(option_index) {
        /* h, help */
        case 0:
        case 1:
        	Usage(argv[0]);
            return 0;
            break;

            /* d, device */
        case 2:
        case 3:
        	Usage(argv[0]);
            dev = strdup(optarg);
            DXL.ComPort->SetPortName(dev);
            break;

        default:
        	Usage(argv[0]);
            return 0;
        }
    }

    if(DXL.Connect() == false)
    {
    	fprintf(stderr, " Fail to open USB2Dyanmixel! [%s] \n\n", dev);
    	return 0;
    }

    char input[128];
    char cmd[80];
    char param[20][30];
    int num_param;
    char* token;
    while(1)
    {
    	printf("[CMD] ");
    	gets(input);
    	fflush(stdin);

    	if(strlen(input) == 0)
    		continue;

    	token = strtok(input, " ");
    	if(token == 0)
    		continue;

    	strcpy(cmd, token);
    	token = strtok(0, " ");
    	num_param = 0;
    	while(token != 0)
    	{
    		strcpy(param[num_param++], token);
    		token = strtok(0, " ");
    	}

    	if(strcmp(cmd, "help") == 0 || strcmp(cmd, "h") == 0 || strcmp(cmd, "?") == 0)
    	{
    		Help();
    	}
    	else if(strcmp(cmd, "ping") == 0)
    	{
    		if(num_param == 0)
    		{
    			fprintf(stderr, " Invalid parameters! \n");
    			continue;
    		}

//.........这里部分代码省略.........
开发者ID:Yunaik,项目名称:thu,代码行数:101,代码来源:monitor.cpp

示例3: main

int main()
{    
    int PresentPos = 0;
    int PresentVel = 0;
    int index = 0, result = COMM_TXFAIL, error = 0, Moving = 1;
    int GoalPos[2] = {-125700, 125700};
    int GoalVel[2] = {-8000, 8000};

    Dynamixel DXL("/dev/ttyUSB0");

    // Open device
    if( DXL.Connect() == 0 )
    {
        printf( "Failed to open USB2Dynamixel!\n" );
        printf( "Press any key to terminate...\n" );
        _getch();
        return 0;
    }
    else
        printf( "Succeed to open USB2Dynamixel!\n" );

    if(DXL.SetBaudrate(DEFAULT_BAUDNUM) == true)
    {
        printf( "Succeed to change the baudrate!\n" );
    }
    else
    {
        printf( "Failed to change the baudrate!\n" );
        printf( "Press any key to terminate...\n" );
        _getch();
        return 0;
    }

    result = DXL.WriteByte(DEFAULT_ID, P_TORQUE_ENABLE, 1, &error);

    if(result == COMM_RXSUCCESS)
    {
        PrintErrorCode(error);
    }
    else
        PrintCommStatus(result);

    while(1)
    {
        printf("Definir Velocidad (-8000,8000) \r\n");
        cin>>GoalVel[0];
        printf( "Presione Enter para continuar!(presione ESC y Enter para salir)\n" );
        if(_getch() == 0x1b)
            break;

        // Write goal position
        //DXL.WriteDWord( DEFAULT_ID, P_GOAL_POSITION_LL, GoalPos[index], &error);
        // Write goal Speed
        result = DXL.WriteDWord( DEFAULT_ID, P_GOAL_VELOCITY_LL, GoalVel[index], &error);
        if(result == COMM_RXSUCCESS)
        {
            PrintErrorCode(error);
        }
        else
            PrintCommStatus(result);
        // Change goal position
        /* for(int i=0;i<1;i++)
        {
            // Read present position
            //result = DXL.ReadDWord(DEFAULT_ID, P_PRESENT_POSITION_LL, (long*) &PresentPos, &error);
            // Read present Velocity
            result = DXL.ReadDWord(DEFAULT_ID, P_PRESENT_VELOCITY_LL, (long*) &PresentVel, &error);
            if( result == COMM_RXSUCCESS )
            {
                printf( "%d   %d\n", GoalVel[index], PresentVel );
                PrintErrorCode(error);
            }
            else
            {
                PrintCommStatus(result);
                break;
            }


        }//while(Moving == 1);*/
        // Change goal position

    }

    // Close device
    DXL.Disconnect();
    printf( "Press Enter key to terminate...\n" );
    _getch();
    return 0;
}
开发者ID:kill4n,项目名称:Kuro_ACM,代码行数:90,代码来源:main.cpp


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