Skip to content
Snippets Groups Projects
SpeedMeasure.cpp 1.14 KiB
Newer Older
Hoop77's avatar
Hoop77 committed
//
// Created by philipp on 10.05.18.
//

Hoop77's avatar
-  
Hoop77 committed
#include <iostream>
Hoop77's avatar
Hoop77 committed
#include "../include/VeloxProtocolLib/Connection.h"

Hoop77's avatar
Hoop77 committed
constexpr float MAX_SPEED = 1.0f;

Hoop77's avatar
Hoop77 committed
int main(int argc, char ** argv)
{
    using namespace veloxProtocol;
    using namespace std::chrono_literals;
Hoop77's avatar
-  
Hoop77 committed

    if (argc < 4)
    {
        std::cerr << "Usage: speed angle time[s]\n";
        return -1;
    }

    float speed = atof(argv[1]);
Hoop77's avatar
Hoop77 committed
    if (std::abs(speed) > MAX_SPEED)
    {
        speed = speed >= 0 ? MAX_SPEED : -MAX_SPEED;
        std::cout << "WARNING: Speed set to 1.0 due to risk of collision!\n";
    }
Hoop77's avatar
-  
Hoop77 committed
    float angle = atof(argv[2]);
    int time = atoi(argv[3]);

Hoop77's avatar
Hoop77 committed
    networking::Networking net;
    std::atomic<bool> running{true};
    auto conn = Connection::create(net);
    conn->open(
        "/dev/ttySAC0",
        []
        {},
        []
        {});

Hoop77's avatar
-  
Hoop77 committed
    conn->setSpeed(speed);
    conn->setSteeringAngle(angle);

Hoop77's avatar
Hoop77 committed
    auto timer = networking::time::Timer::create(net);
    timer->startTimeout(
Hoop77's avatar
-  
Hoop77 committed
        std::chrono::seconds{time},
Hoop77's avatar
Hoop77 committed
        [&]
        {
            conn->setSpeed(0.0f);
            running = false;
        });

    while (running);
    sleep(1);
    return 0;
}