Add encoder with filter
This commit is contained in:
parent
5ecf92426a
commit
8537e8504b
60 changed files with 593 additions and 8208 deletions
|
@ -5,6 +5,14 @@
|
|||
#include <zconf.h>
|
||||
#include "include/messageBuilder.hpp"
|
||||
#include "include/errorMessages.hpp"
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <chrono>
|
||||
|
||||
#include "include/spi.hpp"
|
||||
#include "include/reset.hpp"
|
||||
#include "include/encoder.hpp"
|
||||
#include "include/motor.hpp"
|
||||
#include "include/robot.hpp"
|
||||
|
||||
#define SOCKET_PATH "/tmp/compLib"
|
||||
#define BUFFER_SIZE 64
|
||||
|
@ -84,7 +92,55 @@ google::protobuf::Message *processMessage(const std::string &serializedMessage)
|
|||
}
|
||||
|
||||
int main() {
|
||||
socketServer();
|
||||
// socketServer();
|
||||
Reset::reset_robot();
|
||||
// Spi &spi = Spi::getInstance();
|
||||
// int version = spi.read(1, 1);
|
||||
|
||||
// double count = 20000;
|
||||
// double start_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
// for (int i{0}; i < count; i++){
|
||||
// spi.read(1, 1);
|
||||
// }
|
||||
// double end_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
|
||||
double power = 0;
|
||||
// int port = 0;
|
||||
// long double accumulator = 0;
|
||||
// long double alpha = 0.2;
|
||||
while (power < 100) {
|
||||
power += 0.1;
|
||||
Motor::power(0, power);
|
||||
Motor::power(3, power);
|
||||
|
||||
auto speeds = Motor::get_instance().get_speed();
|
||||
// spdlog::info("{:05.0f} {:05.0f}", speeds.at(0), speeds.at(3));
|
||||
|
||||
// auto start_values = Encoder::read_all();
|
||||
// spdlog::info("{}", start_values.at(3));
|
||||
// auto start_time = std::chrono::high_resolution_clock::now();
|
||||
usleep(1000.0 * (1000.0 / 150.0));
|
||||
// auto end_values = Encoder::read_all();
|
||||
|
||||
// auto elapsed_time = std::chrono::high_resolution_clock::now() - start_time;
|
||||
// long double elapsed_ticks = end_values.at(port) - start_values.at(port);
|
||||
|
||||
// long double elapsed_us = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
// elapsed_time).count();
|
||||
// long double elapsed_s = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
// elapsed_time).count() / 1000000.0;
|
||||
|
||||
// long double vel_ticks_s = elapsed_ticks / elapsed_s;
|
||||
// long double vel_rpm = vel_ticks_s * 60.0L / TICKS_PER_TURN;
|
||||
|
||||
// accumulator = (alpha * vel_rpm) + (1.0 - alpha) * accumulator;
|
||||
|
||||
// spdlog::info("{:05.0f} {:05.0f} {:05.0f} {:05.0f} {:05.0f}", elapsed_us, elapsed_ticks, vel_ticks_s, vel_rpm, accumulator);
|
||||
}
|
||||
|
||||
|
||||
// spdlog::info(count / (end_time - start_time) * 1000.0);
|
||||
// spi.write(Spi::Register::DISPLAY_LINE_1_C0, 1, 66);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue