问题描述
我写了以下代码如何使用箭头键盘按下移动机械臂。但是,当我按下箭头键盘时,在 KLR 2 Baru.exe 中的 0x00007FF610DE1904 处发生了错误未处理异常:0xC0000005:访问冲突读取位置 0x000000BE306C4F20。 这是我的代码:
// Printing array elements
int i,k = 0;
cout << "Start controlling,if you want to stop,please enter ESC" << endl;
while (button != ESC_ASCII_VALUE)
{
button = getch();
if (button == ARROW_UP && k<8)
{
cout << "Naik" << endl;
k < 8;
k = k + 1;
for (int s = 0; s < 4; ++s)
{
dxl_goal_position = numbers[i][k][s];
// Write goal position
dxl_comm_result = packetHandler->write2ByteTxRx(portHandler,servo_id[s],ADDR_MX_GOAL_POSITION,dxl_goal_position,&dxl_error);
if (dxl_comm_result != COMM_SUCCESS)
{
printf("%s\n",packetHandler->getTxRxResult(dxl_comm_result));
}
else if (dxl_error != 0)
{
printf("%s\n",packetHandler->getRxPacketError(dxl_error));
}
cout << "Servo ID: " << servo_id[s] << " & " << "Present Position: " << dxl_goal_position << endl;
}
}
else if (button == ARROW_DOWN && k<8)
{
cout << "Turun" << endl;
k < 8;
k = k - 1;
for (int s = 0; s < 4; ++s)
{
dxl_goal_position = numbers[i][k][s];
// Write goal position
dxl_comm_result = packetHandler->write2ByteTxRx(portHandler,packetHandler->getRxPacketError(dxl_error));
cout << "Servo ID: " << servo_id[s] << " & " << "Present Position: " << dxl_goal_position << endl;
}
}
}
else if (button == ARROW_LEFT && i < 8)
{
cout << "Belok kiri" << endl;
i < 8;
i = i - 1;
for (int s = 0; s < 4; ++s)
{
dxl_goal_position = numbers[i][k][s];
// Write goal position
dxl_comm_result = packetHandler->write2ByteTxRx(portHandler,packetHandler->getRxPacketError(dxl_error));
}
cout << "Servo ID: " << servo_id[s] << " & " << "Present Position: " << dxl_goal_position << endl;
}
}
else if (button == ARROW_RIGHT && i < 8)
{
cout << "Belok kanan" << endl;
i < 8;
i = i + 1;
for (int s = 0; s < 4; ++s)
{
dxl_goal_position = numbers[i][k][s];
// Write goal position
dxl_comm_result = packetHandler->write2ByteTxRx(portHandler,packetHandler->getRxPacketError(dxl_error));
}
cout << "Servo ID: " << servo_id[s] << " & " << "Present Position: " << dxl_goal_position << endl;
}
}
else if (button == ESC_ASCII_VALUE)
break;
}
This is the error I encountered
我需要解决方案。我仍然是这个 C++ 的初学者。谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)