Commit ffc6eecc authored by Daniil Kukushkin's avatar Daniil Kukushkin

Direct motors control implemented

parent 56d3585c
*.bat
*.txt
\ No newline at end of file
*.txt
*.zip
.vscode
\ No newline at end of file
......@@ -607,6 +607,14 @@ void MainController::switchArmDisarm(bool armState)
Serial.write(mavSendBuffer, txSize);
}
void MainController::setMotorSpeed(uint8_t motorNumber, float speedPercent)
{
mavlink_message_t msg;
mavlink_msg_command_long_pack(0, 0, &msg, 0, 0, MAV_CMD_DO_MOTOR_TEST, 0, motorNumber, MOTOR_TEST_THROTTLE_PERCENT, speedPercent, 0, 0, 0, 0);
int16_t txSize = mavlink_msg_to_send_buffer(mavSendBuffer, &msg);
Serial.write(mavSendBuffer, txSize);
}
void MainController::armMotors()
{
switchArmDisarm(true);
......
......@@ -186,6 +186,8 @@ public:
void setLEDsColors(uint8_t forwardR, uint8_t forwardG, uint8_t forwardB, uint8_t backwardR, uint8_t backwardG, uint8_t backwardB);
void setLEDsColors(Color & forwardColor, Color & backwardColor);
void setMotorSpeed(uint8_t motorNumber, float speedPercent); // 'motorNumber' from 1 to 4 (as on board numbers), 'speedPercent' from 0.0 to 100.0
void setFrontLEDColor(uint8_t forwardR, uint8_t forwardG, uint8_t forwardB);
void setBackLEDColor(uint8_t backwardR, uint8_t backwardG, uint8_t backwardB);
......
/*
Copyright (C) 2019 Minibot
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Minibot nor the names
of its contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#include "NanopixCore.h"
using namespace NanopixCore;
MainController & nanopix = MainController::getInstance();
void setup() { }
// ------------------------------------- flightScript ---------------------------------------------
// ------- Напишите свою программу для Nanopix внутри функции flightScript().
// ------- В текущем примере светодиоды переключают свой цвет каждую секунду.
// ------------------------------------------------------------------------------------------------
void flightScript()
{
for(int i = 25; i < 100; i++)
{
nanopix.setMotorSpeed(2, 0);
nanopix.setMotorSpeed(4, 0);
nanopix.setMotorSpeed(1, i);
nanopix.setMotorSpeed(3, i);
nanopix.setFrontLEDColor(Color::Blue);
nanopix.setBackLEDColor(Color::Red);
delay(1000);
nanopix.setMotorSpeed(1, 0);
nanopix.setMotorSpeed(3, 0);
nanopix.setMotorSpeed(2, i);
nanopix.setMotorSpeed(4, i);
nanopix.setFrontLEDColor(Color::Green);
nanopix.setBackLEDColor(Color::Blue);
delay(1000);
}
}
// ------------------------------------------------------------------------------------------------
void loop() {
nanopix.mainRoutine();
if(nanopix.isMissionTriggered())
{
delay(1000);
flightScript();
nanopix.isArmCommandReceived();
nanopix.isMissionTriggered();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment