Ir para o conteúdo principal

Servos de Comando

Este documento foi desenvolvido em parceria com a equipe JUSTICE FTC TEAM #21036

Controles Básicos do Servo

Os servomotores são motores especializados que podem ser controlados para se mover em um ângulo específico em vez de girar continuamente como um motor CC. Para obter mais informações gerais sobre servos, consulte esta página; para obter informações mais detalhadas, consulte https://en.wikipedia.org/wiki/Servo_control

Configuração do Servo Hub

O controle do servo no REVLib é acessado por meio do objeto ServoHub. Esse objeto gerencia os objetos ServoChannel individuais e monitora o dispositivo geral. O objeto ServoChannel controla cada servomotor e monitora sua operação. Ele também contém todos os métodos para configurar e controlar o servo. Ele pode ser acessado conforme mostrado abaixo:


// Initialize the servo hub
ServoHub m_servoHub = new ServoHub(deviceID);

// Obtain a servo channel controller
ServoChannel m_channel0 = m_servoHub.getServoChannel(ChannelId.kChannelId0);
ServoChannel m_channel1 = m_servoHub.getServoChannel(ChannelId.kChannelId1);
...
ServoChannel m_channel5 = m_servoHub.getServoChannel(ChannelId.kChannelId5);

API Docs: ServoHub, ServoChannel


using namespace rev::servohub;
using namespace rev::servohub::ServoChannel;

// Initialize the servo hub
ServoHub m_servoHub{ deviceID };

//Obtain a reference to a servo channel controller
ServoChannel& m_channel0 = m_servoHub.GetServoChannel(ChannelId.kChannelId0);
ServoChannel& m_channel1 = m_servoHub.GetServoChannel(ChannelId.kChannelId1);
...
ServoChannel& m_channel5 = m_servoHub.GetServoChannel(ChannelId.kChannelId5);

API Docs: ServoHub, ServoChannel

Configuração do Período de Pulso do Servo

Em um servomotor, a largura do pulso determinará a distância de giro do motor. O período de pulso, por outro lado, determinará a frequência com que o pulso é enviado ao servo. O ServoHub é compatível com um período de pulso de 4,5 a 20 ms (especificado em microssegundos). O ServoHub é compatível com um período de pulso separado para cada banco, compondo os servos 0-2 e 3-5, respectivamente. Essas configurações podem ser acessadas conforme mostrado abaixo:

// Set the pulse period for channels 0-2 to 5ms (5000 microseconds)
m_servoHub.setBankPulsePeriod(ServoHub.Bank.kBank0_2, 5000);

// Set the pulse period for channels 3-5 to 20ms (20000 microseconds)
m_servoHub.setBankPulsePeriod(ServoHub.Bank.kBank3_5, 20000);

API Docs: setBankPulsePeriod

using namespace rev::servohub;

// Set the pulse period for channels 0-2 to 5ms (5000 microseconds)
m_servoHub.SetBankPulsePeriod(ServoHub::Bank::kBank0_2, 5000);

// Set the pulse period for channels 3-5 to 20ms (20000 microseconds)
m_servoHub.SetBankPulsePeriod(ServoHub::Bank::kBank3_5, 20000);

API Docs: SetBankPulsePeriod

Controle de um Servo Individual

Os servos individuais são controlados por meio dos objetos ServoChannel. Como mostrado acima, você obtém uma referência a um objeto ServoChannel chamando o método getServoChannel() no ServoHub. Você pode definir o seguinte em um ServoChannel:

  • PulseWidth (Largura de pulso) - determina a posição do servo (500 a 2500 microssegundos).

  • Enabled - ativa/desativa o servo - quando desativado, o servo manterá a energia de acordo com o DisableBehavior configurado para o canal específico.

  • Powered (Alimentado) - liga/desliga a alimentação do servo


// Power on channels 0, 1, and 4
m_channel0.setPowered(true);
m_channel1.setPowered(true);
m_channel4.setPowered(true);

// Enabled them as well
m_channel0.setEnabled(true);
m_channel1.setEnabled(true);
m_channel4.setEnabled(true)

// Set the servo on channel 0 to the center (1500 microseconds)
m_channel0.setPulseWidth(1500);

// Set the servo on channel 1 to the far left (500 microseconds)
m_channel1.setPulseWidth(500);

// Set the servo on channel 4 to the far right(2500 microseconds)
m_channel4.setPulseWidth(2500);

API Docs: setPulseWidth, setPowered, setEnabled

using namespace rev::servohub;

// Power on channels 0, 1, and 4
m_channel0.SetPowered(true);
m_channel1.SetPowered(true);
m_channel4.SetPowered(true);

// Enabled them as well
m_channel0.SetEnabled(true);
m_channel1.SetEnabled(true);
m_channel4.SetEnabled(true)

// Set the servo on channel 0 to the center (1500 microseconds)
m_channel0.SetPulseWidth(1500);

// Set the servo on channel 1 to the far left (500 microseconds)
m_channel1.SetPulseWidth(500);

// Set the servo on channel 4 to the far right(2500 microseconds)
m_channel4.SetPulseWidth(2500);

API Docs: SetPulseWidth, SetEnabled, SetPowered