🕹️ Interfaces de Controle para Humanoides
Objetivo do Módulo
Dominar as principais formas de controlar um robô humanoide: desde joysticks tradicionais até realidade virtual e comandos de voz.
🎮 Tipos de Interface de Controle
Comparação Geral
| Interface | Precisão | Latência | Curva de Aprendizado | Custo | Melhor Para |
|---|---|---|---|---|---|
| Teclado | Baixa | Baixa (10ms) | Fácil | $0 | Testes iniciais |
| Joystick Gamepad | Média | Baixa (15ms) | Fácil | $30-60 | Operação geral |
| Joystick Profissional | Alta | Baixa (5ms) | Moderada | $200-500 | Tarefas de precisão |
| SpaceMouse | Muito Alta | Baixa (5ms) | Difícil | $150-400 | Manipulação 6-DOF |
| Tablet Touchscreen | Média | Média (50ms) | Fácil | $300-1000 | Supervisão mobile |
| VR (Realidade Virtual) | Muito Alta | Média (30ms) | Difícil | $300-1500 | Teleoperação imersiva |
| Comandos de Voz | Baixa | Alta (200ms) | Fácil | $0 | Comandos de alto nível |
| Motion Capture | Altíssima | Baixa (10ms) | Difícil | $5k+ | Imitação de movimentos |
⌨️ Controle por Teclado
Quando Usar
- ✅ Testes rápidos em simulação
- ✅ Aprender comandos básicos
- ✅ Desenvolvimento de software (debug)
- ❌ NUNCA em hardware real (muito impreciso)
Mapeamento Básico ROS2
- 🚶 Movimento Base
- 🦾 Controle de Juntas
Pacote: teleop_twist_keyboard
# Instalar
sudo apt install ros-humble-teleop-twist-keyboard
# Executar
ros2 run teleop_twist_keyboard teleop_twist_keyboard
Teclas Padrão:
i (frente)
j k l (esquerda, parar, direita)
, (trás)
u o (girar enquanto anda)
m . (girar enquanto anda para trás)
q/z : Aumentar/diminuir velocidade linear (10%)
w/x : Aumentar/diminuir velocidade angular (10%)
CTRL-C para sair
Script Python Customizado:
import rclpy
from rclpy.node import Node
from sensor_msgs.msg import JointState
import sys
import termios
import tty
class KeyboardJointControl(Node):
def __init__(self):
super().__init__('keyboard_joint_control')
self.publisher = self.create_publisher(JointState, '/joint_commands', 10)
# Estado atual das juntas
self.joint_positions = {
'left_shoulder': 0.0,
'right_shoulder': 0.0,
'left_knee': 0.0,
'right_knee': 0.0,
}
self.current_joint = 'left_shoulder'
self.step = 0.1 # radianos por tecla
def get_key(self):
"""Captura uma tecla sem esperar Enter"""
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
key = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return key
def process_key(self, key):
if key == 'w': # Aumentar ângulo
self.joint_positions[self.current_joint] += self.step
elif key == 's': # Diminuir ângulo
self.joint_positions[self.current_joint] -= self.step
elif key == '1': # Selecionar junta
self.current_joint = 'left_shoulder'
elif key == '2':
self.current_joint = 'right_shoulder'
elif key == '3':
self.current_joint = 'left_knee'
elif key == '4':
self.current_joint = 'right_knee'
elif key == 'q': # Sair
return False
# Publicar novo estado
msg = JointState()
msg.name = list(self.joint_positions.keys())
msg.position = list(self.joint_positions.values())
self.publisher.publish(msg)
print(f'Junta: {self.current_joint} | Ângulo: {self.joint_positions[self.current_joint]:.2f} rad')
return True
def run(self):
print("=== Controle de Juntas por Teclado ===")
print("1/2/3/4: Selecionar junta")
print("W/S: Aumentar/Diminuir ângulo")
print("Q: Sair\n")
running = True
while running:
key = self.get_key()
running = self.process_key(key)
def main():
rclpy.init()
node = KeyboardJointControl()
node.run()
rclpy.shutdown()
🎮 Joystick Gamepad (Xbox/PlayStation)
Hardware Recomendado
- 💰 Entrada ($30-60)
- 🚀 Intermediário ($60-150)
- 💎 Profissional ($200-500)
Xbox One Controller (com fio)
- Preço: $40 (Amazon)
- Conexão: USB
- Latência: ~15ms
- Compatibilidade: Linux nativo (driver
xpad)
Configuração:
# Verificar se foi detectado
sudo apt install joystick
jstest /dev/input/js0
# Instalar pacote ROS2
sudo apt install ros-humble-joy
sudo apt install ros-humble-teleop-twist-joy
PlayStation 5 DualSense
- Preço: $70
- Conexão: USB-C ou Bluetooth
- Latência: ~10ms (USB), ~20ms (BT)
- Extras: Feedback háptico avançado, gatilhos adaptativos
Vantagens:
- ✅ Gatilhos analógicos (melhor controle de velocidade)
- ✅ Feedback tátil (sentir colisões no jogo)
- ✅ Bateria interna (uso sem fio)
Driver Linux:
# Instalar suporte PS5
sudo apt install ds5-tool
Logitech Extreme 3D Pro (Joystick de Voo)
- Preço: $40 (mas design profissional)
- Conexão: USB
- Controles: 1 stick 3-axis + 12 botões + throttle
- Uso: Controle fino de movimentos (braços, câmera)
Thrustmaster HOTAS (Hands On Throttle And Stick)
- Preço: $250-500
- Controles: 2 sticks independentes + pedais (opcional)
- Uso: Teleoperação avançada (uma mão = movimento, outra = braços)
Configuração ROS2 Joy
Arquivo de configuração: config/joy_teleop.yaml
teleop_twist_joy_node:
ros__parameters:
# Eixos do joystick (valores de 0 a N, conforme seu controle)
axis_linear: 1 # Stick esquerdo vertical (frente/trás)
axis_angular: 2 # Stick direito horizontal (girar)
# Escala de velocidade
scale_linear: 1.0 # m/s máximo
scale_angular: 2.0 # rad/s máximo
# Botão "turbo" (segurar para velocidade máxima)
enable_button: 5 # Botão RB (bumper direito)
# Botão "slow mode" (precisão)
enable_turbo_button: 4 # Botão LB (bumper esquerdo)