mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-01 02:55:07 +08:00
VescDriver: support commanding motor duty cycle
This commit is contained in:
@@ -39,6 +39,14 @@
|
|||||||
#include "VescDriver.hpp"
|
#include "VescDriver.hpp"
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
|
|
||||||
|
void VescDriver::commandDutyCycle(float duty_cycle)
|
||||||
|
{
|
||||||
|
uint8_t command[5] {VescCommand::SET_DUTY};
|
||||||
|
uint16_t index{1};
|
||||||
|
insertInt32(command, index, static_cast<int32_t>(duty_cycle * 100000.f));
|
||||||
|
sendPacket(command, 5);
|
||||||
|
}
|
||||||
|
|
||||||
void VescDriver::commandCurrent(float current)
|
void VescDriver::commandCurrent(float current)
|
||||||
{
|
{
|
||||||
uint8_t command[5] {VescCommand::SET_CURRENT};
|
uint8_t command[5] {VescCommand::SET_CURRENT};
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ public:
|
|||||||
VescDriver(VescWritable *vesc_writable) : _vesc_writable(vesc_writable) {};
|
VescDriver(VescWritable *vesc_writable) : _vesc_writable(vesc_writable) {};
|
||||||
~VescDriver() = default;
|
~VescDriver() = default;
|
||||||
|
|
||||||
|
void commandDutyCycle(float duty_cycle);
|
||||||
void commandCurrent(float current);
|
void commandCurrent(float current);
|
||||||
void commandBrakeCurrent(float current);
|
void commandBrakeCurrent(float current);
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ void VescDevice::Run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
_vesc_driver.requestFirmwareVersion();
|
_vesc_driver.requestFirmwareVersion();
|
||||||
_vesc_driver.commandCurrent(.5f);
|
_vesc_driver.commandDutyCycle(.05f);
|
||||||
|
|
||||||
// Check the number of bytes available in the buffer
|
// Check the number of bytes available in the buffer
|
||||||
int bytes_available{0};
|
int bytes_available{0};
|
||||||
|
|||||||
Reference in New Issue
Block a user