所以我正在使用java在我的移动应用程序中开发一个控制器,目前每当我触摸按钮时,它都会连续发送3个数据。当释放按钮时它应该只发送一个数据和另一个数据
我可以在按钮释放时设置获取数据,但由于传递了很多数据,所以不准确
upbtn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
rosbridge.Publish("/set_velocity", nav_ctrl);
if(event.getAction() == ACTION_DOWN) {
nav_ctrl.linear.x = 0.6;
nav_ctrl.angular.z = 0;
return true;
} else if (event.getAction() != MotionEvent.ACTION_UP) {
return false;
}
nav_ctrl.linear.x = 0;
nav_ctrl.angular.z = 0;
return false;
}
});
downbtn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
rosbridge.Publish("/set_velocity", nav_ctrl);
if(event.getAction() == ACTION_MOVE) {
nav_ctrl.linear.x = -0.6;
nav_ctrl.angular.z = 0;
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
nav_ctrl.linear.x = 0;
nav_ctrl.angular.z = 0;
}
return false;
}
});
leftbtn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
rosbridge.Publish("/set_velocity", nav_ctrl);
if(event.getAction() == ACTION_DOWN) {
nav_ctrl.linear.x = 1.2;
nav_ctrl.angular.z = 0;
return true;
} else if (event.getAction() == MotionEvent.ACTION_UP) {
leftbtn.performClick();
nav_ctrl.linear.x = 0;
nav_ctrl.angular.z = 0;
}
return false;
}
});
rightbtn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
rosbridge.Publish("/set_velocity", nav_ctrl);
if(event.getAction() == ACTION_DOWN) {
nav_ctrl.linear.x = -1.2;
nav_ctrl.angular.z = 0;
return true;
} else if (event.getAction() == MotionEvent.ACTION_UP) {
nav_ctrl.linear.x = 0;
nav_ctrl.angular.z = 0;
}
return false;
}
});
}
我希望只发送一行数据,例如:"angular":{"x":0.0,"y":0.0,"z":0.0},"linear":{"x":-0.6," y":0.0,"z":0.0}},
输出相似,但交付了多个数据