我希望通过使用PS4控制器或Xbox 360控制器来控制ROV。我计划通过将控制器连接到计算机,然后将其发送到 ROV 来做到这一点。关于该项目的一些背景信息是,我们将控制器放在顶部,将其发送到计算机,然后我们将通过以太网从计算机发送到ROV上的Arduino。
我了解到,通过使用 Processing 在 PS3 控制器上这是可能的,因为另一个团队做到了,但我不熟悉这种语言,也没有 PS3 控制器。但是,我有一个PS4和Xbox 360控制器。
根据我的研究,SDL 可能是一个选择,但我正在寻求比我更有经验的人的建议。
我的问题被生气的模组删除了,因为它是"不相关的",但我问了同样的问题。无论如何,我像这样使用 SFML 实现了我的 PS4 控制器支持。其他简单的可能性是 SDL。我猜XBox也会一样。玩得愉快
这里有一些示例代码..
sf::Joystick::update();
// Is joystick #0 connected?
m_bGamepadConnected = sf::Joystick::isConnected(0);
if(!m_bGamepadConnected) {
return;
}
// Does joystick #0 define a X axis?
m_bStickLX = sf::Joystick::hasAxis(0, sf::Joystick::X);
m_bStickLY = sf::Joystick::hasAxis(0, sf::Joystick::Y);
m_bStickRX = sf::Joystick::hasAxis(0, sf::Joystick::Z);
m_bStickRY = sf::Joystick::hasAxis(0, sf::Joystick::R);
m_bStickL2 = sf::Joystick::hasAxis(0, sf::Joystick::U);
m_bStickR2 = sf::Joystick::hasAxis(0, sf::Joystick::V);
m_tJoystick.start(5);
QObject::connect(&m_tJoystick, SIGNAL(timeout() ), this, SLOT(updateGamepad() ) );
这可能会对您有所帮助..
sf::Joystick::update();
float fStickLX = 0;
float fStickLY = 0;
float fStickRX = 0;
float fStickRY = 0;
float fStickL2 = 0;
float fStickR2 = 0;
// What's the current position of the analog sticks
if(m_bStickLX) {
fStickLX = sf::Joystick::getAxisPosition(0, sf::Joystick::X) / 100;
}
if(m_bStickLY) {
fStickLY = sf::Joystick::getAxisPosition(0, sf::Joystick::Y) / 100;
}
if(m_bStickRX) {
fStickRX = sf::Joystick::getAxisPosition(0, sf::Joystick::Z) / 100;
}
if(m_bStickRY) {
fStickRY = sf::Joystick::getAxisPosition(0, sf::Joystick::R) / 100;
}
// R2 and L2
if(m_bStickL2) {
fStickL2 = sf::Joystick::getAxisPosition(0, sf::Joystick::U) + 100;
fStickL2 /= 200;
}
if(m_bStickR2) {
fStickR2 = sf::Joystick::getAxisPosition(0, sf::Joystick::V) + 100;
fStickR2 /= 200;
}
if(m_fStickLX != 0 || m_fStickLY != 0 || m_fStickRX != 0 || m_fStickRY != 0 || m_fStickL2 != fStickL2 || m_fStickR2 != fStickR2) {
m_bGamepadInUse = true;
} else {
m_bGamepadInUse = false;
}
m_fStickLX = fStickLX;
m_fStickLY = fStickLY;
m_fStickRX = fStickRX;
m_fStickRY = fStickRY;
m_fStickL2 = fStickL2;
m_fStickR2 = fStickR2;
m_bButLPressed = isButtonPressed(0, 0);
m_bButDPressed = isButtonPressed(0, 1);
m_bButRPressed = isButtonPressed(0, 2);
m_bButTPressed = isButtonPressed(0, 3);
//qDebug() << "m_bButDPressed pressed: " << m_bButDPressed;
static bool bArmToggle = false;
if(m_bButDPressed && !bArmToggle) {
m_bDeviceArmed = m_bDeviceArmed ? false : true;
bArmToggle = true;
qDebug() << "Device armed?: " << m_bDeviceArmed;
}
if(bArmToggle && !m_bButDPressed) {
bArmToggle = false;
}