mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 21:03:34 +08:00
Merge branch 'master' of github.com:PX4/Firmware into fmuv2_bringup
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
#include "BlockSysIdent.hpp"
|
||||
|
||||
BlockSysIdent::BlockSysIdent() :
|
||||
Block(NULL, "SYSID"),
|
||||
_freq(this, "FREQ"),
|
||||
_ampl(this, "AMPL")
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#include <controllib/block/Block.hpp>
|
||||
#include <controllib/block/BlockParam.hpp>
|
||||
|
||||
class BlockSysIdent : public control::Block {
|
||||
public:
|
||||
BlockSysIdent();
|
||||
private:
|
||||
control::BlockParam<float> _freq;
|
||||
control::BlockParam<float> _ampl;
|
||||
};
|
||||
@@ -45,9 +45,16 @@
|
||||
#include "md25.hpp"
|
||||
#include <poll.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <systemlib/err.h>
|
||||
#include <arch/board/board.h>
|
||||
#include <mavlink/mavlink_log.h>
|
||||
|
||||
#include <controllib/uorb/UOrbPublication.hpp>
|
||||
#include <uORB/topics/debug_key_value.h>
|
||||
#include <drivers/drv_hrt.h>
|
||||
|
||||
// registers
|
||||
enum {
|
||||
@@ -72,6 +79,9 @@ enum {
|
||||
REG_COMMAND_RW,
|
||||
};
|
||||
|
||||
// File descriptors
|
||||
static int mavlink_fd;
|
||||
|
||||
MD25::MD25(const char *deviceName, int bus,
|
||||
uint16_t address, uint32_t speed) :
|
||||
I2C("MD25", deviceName, bus, address, speed),
|
||||
@@ -106,7 +116,8 @@ MD25::MD25(const char *deviceName, int bus,
|
||||
setMotor2Speed(0);
|
||||
resetEncoders();
|
||||
_setMode(MD25::MODE_UNSIGNED_SPEED);
|
||||
setSpeedRegulation(true);
|
||||
setSpeedRegulation(false);
|
||||
setMotorAccel(10);
|
||||
setTimeout(true);
|
||||
}
|
||||
|
||||
@@ -298,6 +309,12 @@ int MD25::setDeviceAddress(uint8_t address)
|
||||
return OK;
|
||||
}
|
||||
|
||||
int MD25::setMotorAccel(uint8_t accel)
|
||||
{
|
||||
return _writeUint8(REG_ACCEL_RATE_RW,
|
||||
accel);
|
||||
}
|
||||
|
||||
int MD25::setMotor1Speed(float value)
|
||||
{
|
||||
return _writeUint8(REG_SPEED1_RW,
|
||||
@@ -451,12 +468,12 @@ int md25Test(const char *deviceName, uint8_t bus, uint8_t address)
|
||||
MD25 md25("/dev/md25", bus, address);
|
||||
|
||||
// print status
|
||||
char buf[200];
|
||||
char buf[400];
|
||||
md25.status(buf, sizeof(buf));
|
||||
printf("%s\n", buf);
|
||||
|
||||
// setup for test
|
||||
md25.setSpeedRegulation(true);
|
||||
md25.setSpeedRegulation(false);
|
||||
md25.setTimeout(true);
|
||||
float dt = 0.1;
|
||||
float speed = 0.2;
|
||||
@@ -550,4 +567,68 @@ int md25Test(const char *deviceName, uint8_t bus, uint8_t address)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int md25Sine(const char *deviceName, uint8_t bus, uint8_t address, float amplitude, float frequency)
|
||||
{
|
||||
printf("md25 sine: starting\n");
|
||||
|
||||
// setup
|
||||
MD25 md25("/dev/md25", bus, address);
|
||||
|
||||
// print status
|
||||
char buf[400];
|
||||
md25.status(buf, sizeof(buf));
|
||||
printf("%s\n", buf);
|
||||
|
||||
// setup for test
|
||||
md25.setSpeedRegulation(false);
|
||||
md25.setTimeout(true);
|
||||
float dt = 0.01;
|
||||
float t_final = 60.0;
|
||||
float prev_revolution = md25.getRevolutions1();
|
||||
|
||||
// debug publication
|
||||
control::UOrbPublication<debug_key_value_s> debug_msg(NULL,
|
||||
ORB_ID(debug_key_value));
|
||||
|
||||
// sine wave for motor 1
|
||||
md25.resetEncoders();
|
||||
while (true) {
|
||||
|
||||
// input
|
||||
uint64_t timestamp = hrt_absolute_time();
|
||||
float t = timestamp/1000000.0f;
|
||||
|
||||
float input_value = amplitude*sinf(2*M_PI*frequency*t);
|
||||
md25.setMotor1Speed(input_value);
|
||||
|
||||
// output
|
||||
md25.readData();
|
||||
float current_revolution = md25.getRevolutions1();
|
||||
|
||||
// send input message
|
||||
//strncpy(debug_msg.key, "md25 in ", 10);
|
||||
//debug_msg.timestamp_ms = 1000*timestamp;
|
||||
//debug_msg.value = input_value;
|
||||
//debug_msg.update();
|
||||
|
||||
// send output message
|
||||
strncpy(debug_msg.key, "md25 out ", 10);
|
||||
debug_msg.timestamp_ms = 1000*timestamp;
|
||||
debug_msg.value = current_revolution;
|
||||
debug_msg.update();
|
||||
|
||||
if (t > t_final) break;
|
||||
|
||||
// update for next step
|
||||
prev_revolution = current_revolution;
|
||||
|
||||
// sleep
|
||||
usleep(1000000 * dt);
|
||||
}
|
||||
md25.setMotor1Speed(0);
|
||||
|
||||
printf("md25 sine complete\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// vi:noet:smarttab:autoindent:ts=4:sw=4:tw=78
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
|
||||
#include <poll.h>
|
||||
#include <stdio.h>
|
||||
#include <controllib/block/UOrbSubscription.hpp>
|
||||
#include <controllib/uorb/UOrbSubscription.hpp>
|
||||
#include <uORB/topics/actuator_controls.h>
|
||||
#include <drivers/device/i2c.h>
|
||||
|
||||
@@ -212,6 +212,19 @@ public:
|
||||
*/
|
||||
int setDeviceAddress(uint8_t address);
|
||||
|
||||
/**
|
||||
* set motor acceleration
|
||||
* @param accel
|
||||
* controls motor speed change (1-10)
|
||||
* accel rate | time for full fwd. to full rev.
|
||||
* 1 | 6.375 s
|
||||
* 2 | 1.6 s
|
||||
* 3 | 0.675 s
|
||||
* 5(default) | 1.275 s
|
||||
* 10 | 0.65 s
|
||||
*/
|
||||
int setMotorAccel(uint8_t accel);
|
||||
|
||||
/**
|
||||
* set motor 1 speed
|
||||
* @param normSpeed normalize speed between -1 and 1
|
||||
@@ -290,4 +303,7 @@ private:
|
||||
// unit testing
|
||||
int md25Test(const char *deviceName, uint8_t bus, uint8_t address);
|
||||
|
||||
// sine testing
|
||||
int md25Sine(const char *deviceName, uint8_t bus, uint8_t address, float amplitude, float frequency);
|
||||
|
||||
// vi:noet:smarttab:autoindent:ts=4:sw=4:tw=78
|
||||
|
||||
@@ -82,7 +82,7 @@ usage(const char *reason)
|
||||
if (reason)
|
||||
fprintf(stderr, "%s\n", reason);
|
||||
|
||||
fprintf(stderr, "usage: md25 {start|stop|status|search|test|change_address}\n\n");
|
||||
fprintf(stderr, "usage: md25 {start|stop|read|status|search|test|change_address}\n\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -136,6 +136,28 @@ int md25_main(int argc, char *argv[])
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "sine")) {
|
||||
|
||||
if (argc < 6) {
|
||||
printf("usage: md25 sine bus address amp freq\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
const char *deviceName = "/dev/md25";
|
||||
|
||||
uint8_t bus = strtoul(argv[2], nullptr, 0);
|
||||
|
||||
uint8_t address = strtoul(argv[3], nullptr, 0);
|
||||
|
||||
float amplitude = atof(argv[4]);
|
||||
|
||||
float frequency = atof(argv[5]);
|
||||
|
||||
md25Sine(deviceName, bus, address, amplitude, frequency);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "probe")) {
|
||||
if (argc < 4) {
|
||||
printf("usage: md25 probe bus address\n");
|
||||
@@ -162,6 +184,29 @@ int md25_main(int argc, char *argv[])
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "read")) {
|
||||
if (argc < 4) {
|
||||
printf("usage: md25 read bus address\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
const char *deviceName = "/dev/md25";
|
||||
|
||||
uint8_t bus = strtoul(argv[2], nullptr, 0);
|
||||
|
||||
uint8_t address = strtoul(argv[3], nullptr, 0);
|
||||
|
||||
MD25 md25(deviceName, bus, address);
|
||||
|
||||
// print status
|
||||
char buf[400];
|
||||
md25.status(buf, sizeof(buf));
|
||||
printf("%s\n", buf);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
if (!strcmp(argv[1], "search")) {
|
||||
if (argc < 3) {
|
||||
printf("usage: md25 search bus\n");
|
||||
@@ -246,7 +291,7 @@ int md25_thread_main(int argc, char *argv[])
|
||||
uint8_t address = strtoul(argv[4], nullptr, 0);
|
||||
|
||||
// start
|
||||
MD25 md25("/dev/md25", bus, address);
|
||||
MD25 md25(deviceName, bus, address);
|
||||
|
||||
thread_running = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user