示例#1
0
void Processor::sendRadioData() {
    Packet::RadioTx* tx = _state.logFrame->mutable_radio_tx();
    tx->set_txmode(Packet::RadioTx::UNICAST);

    // Halt overrides normal motion control, but not joystick
    if (_state.gameState.halt()) {
        // Force all motor speeds to zero
        for (OurRobot* r : _state.self) {
            Packet::Control* control = r->control;
            control->set_xvelocity(0);
            control->set_yvelocity(0);
            control->set_avelocity(0);
            control->set_dvelocity(0);
            control->set_kcstrength(0);
            control->set_shootmode(Packet::Control::KICK);
            control->set_triggermode(Packet::Control::STAND_DOWN);
            control->set_song(Packet::Control::STOP);
        }
    }

    // Add RadioTx commands for visible robots and apply joystick input
    for (OurRobot* r : _state.self) {
        if (r->visible || _manualID == r->shell()) {
            Packet::Robot* txRobot = tx->add_robots();

            // Copy motor commands.
            // Even if we are using the joystick, this sets robot_id and the
            // number of motors.
            txRobot->CopyFrom(r->robotPacket);

            if (r->shell() == _manualID) {
                const JoystickControlValues controlVals =
                    getJoystickControlValues();
                applyJoystickControls(controlVals, txRobot->mutable_control(),
                                      r);
            }
        }
    }

    if (_radio) {
        _radio->send(*_state.logFrame->mutable_radio_tx());
    }
}
示例#2
0
void Processor::sendRadioData() {
    Packet::RadioTx* tx = _state.logFrame->mutable_radio_tx();

    // Halt overrides normal motion control, but not joystick
    if (_state.gameState.halt()) {
        // Force all motor speeds to zero
        for (OurRobot* r : _state.self) {
            Packet::RadioTx::Robot& txRobot = r->radioTx;
            txRobot.set_body_x(0);
            txRobot.set_body_y(0);
            txRobot.set_body_w(0);
            txRobot.set_kick(0);
            txRobot.set_dribbler(0);
        }
    }

    // Add RadioTx commands for visible robots and apply joystick input
    for (OurRobot* r : _state.self) {
        if (r->visible || _manualID == r->shell()) {
            Packet::RadioTx::Robot* txRobot = tx->add_robots();

            // Copy motor commands.
            // Even if we are using the joystick, this sets robot_id and the
            // number of motors.
            txRobot->CopyFrom(r->radioTx);

            if (r->shell() == _manualID) {
                JoystickControlValues controlVals = getJoystickControlValues();
                applyJoystickControls(controlVals, txRobot, r);
            }
        }
    }

    if (_radio) {
        _radio->send(*_state.logFrame->mutable_radio_tx());
    }
}