本文整理汇总了C++中Dynamixel::SetBaudrate方法的典型用法代码示例。如果您正苦于以下问题:C++ Dynamixel::SetBaudrate方法的具体用法?C++ Dynamixel::SetBaudrate怎么用?C++ Dynamixel::SetBaudrate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dynamixel
的用法示例。
在下文中一共展示了Dynamixel::SetBaudrate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
PingInfo *data = new PingInfo();
for(int i = 0; i < num_param; i++)
{
if(DXL.Ping(atoi(param[i]), data, 0) == COMM_RXSUCCESS)
{
fprintf(stderr, " ... SUCCESS \r");
fprintf(stderr, " [ID:%.3d] Model No : %.5d (0x%.2X 0x%.2X) \n",
data->ID, data->ModelNumber, DXL_LOBYTE(data->ModelNumber), DXL_HIBYTE(data->ModelNumber));
}
else
{
fprintf(stderr, " ... FAIL \r");
fprintf(stderr, " [ID:%.3d] \n", atoi(param[i]));
}
}
fprintf(stderr, "\n");
}
else if(strcmp(cmd, "scan") == 0)
{
Scan();
}
else if(strcmp(cmd, "broadcast") == 0)
{
Broadcast();
}
else if(strcmp(cmd, "baud") == 0)
{
if(num_param != 1)
{
fprintf(stderr, " Invalid parameters! \n");
continue;
}
if(DXL.SetBaudrate(atoi(param[0])) == false)
fprintf(stderr, " Failed to change baudrate! \n");
else
fprintf(stderr, " Success to change baudrate! [ BAUD NUM: %d ]\n", atoi(param[0]));
}
else if(strcmp(cmd, "wrb") == 0 || strcmp(cmd, "w") == 0)
{
if(num_param != 3)
{
fprintf(stderr, " Invalid parameters! \n");
continue;
}
Write(atoi(param[0]), atoi(param[1]), atoi(param[2]), 1);
}
else if(strcmp(cmd, "wrw") == 0)
{
if(num_param != 3)
{
fprintf(stderr, " Invalid parameters! \n");
continue;
}
Write(atoi(param[0]), atoi(param[1]), atoi(param[2]), 2);
}
else if(strcmp(cmd, "wrd") == 0)
{
if(num_param != 3)
{
fprintf(stderr, " Invalid parameters! \n");
continue;
}
示例2: main
int main()
{
int id[NUM_ACTUATOR];
float phase[NUM_ACTUATOR];
float theta = 0;
int AmpPos = 150000;
int GoalPos;
int i;
int result;
// Initialize id and phase
for( i=0; i < NUM_ACTUATOR; i++ )
{
id[i] = i+1;
phase[i] = 2*PI * (float)i / (float)NUM_ACTUATOR;
}
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;
}
unsigned char param[NUM_ACTUATOR*(1+4)];
DXL.WriteByte(1, P_TORQUE_ENABLE, 1, 0);
DXL.WriteByte(2, P_TORQUE_ENABLE, 1, 0);
while(1)
{
printf( "Press any key to continue!(press ESC to quit)\n" );
if(_getch() == 0x1b)
break;
theta = 0;
do
{
// Make syncwrite packet
for(i = 0; i < NUM_ACTUATOR; i++)
{
GoalPos = (int)((sin(theta+phase[i])) * (double)AmpPos);
param[i*(1+4)+0] = (unsigned char)id[i];
param[i*(1+4)+1] = DXL_LOBYTE(DXL_LOWORD(GoalPos));
param[i*(1+4)+2] = DXL_HIBYTE(DXL_LOWORD(GoalPos));
param[i*(1+4)+3] = DXL_LOBYTE(DXL_HIWORD(GoalPos));
param[i*(1+4)+4] = DXL_HIBYTE(DXL_HIWORD(GoalPos));
}
printf("%d\n", GoalPos);
result = DXL.SyncWrite(P_GOAL_POSITION_LL, 4, param, NUM_ACTUATOR*(1+4));
if( result != COMM_RXSUCCESS )
{
PrintCommStatus(result);
break;
}
theta += STEP_THETA;
usleep(CONTROL_PERIOD*1000);
}while(theta < 2*PI);
}
DXL.Disconnect();
printf( "Press any key to terminate...\n" );
_getch();
return 0;
}
示例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;
}