torcsclient.h 1.35 KB
Newer Older
Svetlana's avatar
Svetlana committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
#pragma once

#include <cstdint>
#include <array>
#include <memory>

namespace torcs
{

constexpr auto IMAGE_WIDTH = 640;
constexpr auto IMAGE_HEIGHT = 480;
constexpr auto IMAGE_CHANNELS = 1;
constexpr auto IMAGE_SIZE_BYTES = IMAGE_WIDTH*IMAGE_HEIGHT*IMAGE_CHANNELS;

struct shared_use_st
{
    int written = 0;  //a label, if 1: available to read, if 0: available to write
    uint8_t data[IMAGE_SIZE_BYTES];  // image data field
    int control = 0;
    int pause = 0;
    double fast = 0.0;

    double dist_L = 0.0;
    double dist_R = 0.0;

    double toMarking_L = 0.0;
    double toMarking_M = 0.0;
    double toMarking_R = 0.0;

    double dist_LL = 0.0;
    double dist_MM = 0.0;
    double dist_RR = 0.0;

    double toMarking_LL = 0.0;
    double toMarking_ML = 0.0;
    double toMarking_MR = 0.0;
    double toMarking_RR = 0.0;

    double toMiddle = 0.0;
    double angle = 0.0;
    double speed = 0.0;

    double steerCmd = 0.0;
    double accelCmd = 0.0;
    double brakeCmd = 0.0;
};

struct Command
{
    double steerCmd = 0.0;
    double accelCmd = 0.0;
    double brakeCmd = 0.0;
};

using DataContainer = std::array<uint8_t, IMAGE_SIZE_BYTES>;

class TorcsClient
{
public:
    TorcsClient();
    std::unique_ptr<DataContainer> getScreenshot();
    void sendCommand(Command cmd);

private:
    struct shared_use_st *shared;
    bool connected = false;
};

}