0

我希望通过使用 PS4 控制器或 Xbox 360 控制器来控制 ROV。我计划通过将控制器连接到计算机然后将其发送到 ROV 来做到这一点。关于该项目的一些背景信息是,我们在顶部有控制器,它将它发送到计算机,然后我们将通过以太网从计算机发送到 ROV 上的 Arduino。

我了解到这可以通过使用 Processing 在 PS3 控制器上实现,因为另一个团队这样做了,但我不熟悉那种语言并且没有 PS3 控制器。但是,我有一个 PS4 和 Xbox 360 控制器。

根据我的研究,SDL 可能是一个选择,但我正在寻求比我更有经验的人的建议。

4

1 回答 1

0

我的问题被生气的模组删除了,因为它“不相关”,但我问了同样的问题。无论如何,我用这样的 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;
}
于 2014-11-17T23:17:42.377 回答