Dependencies:   SimpleMapSerialization serial_communication

communication.cpp

Committer:
inst
Date:
2016-03-31
Revision:
0:8b0edcbd3b87
Child:
2:074942a78af1

File content as of revision 0:8b0edcbd3b87:

#include "communication.hpp"
#include "moving_object.hpp"
#include "serial_communication.hpp"

#include "mbed_stl.hpp"


#include "mbed.h"

communication* communication::instance_ = NULL;

node_system::moving_object::CONTROL_MODE communication::get_mode() const {
    return node_system::moving_object::MANUAL_MODE;
}

communication::vector2f communication::get_velocity() const {
    uint32_t iv[] = {
        serial_communication::instance()->get_data("stkLX"),
        serial_communication::instance()->get_data("stkLY")
    };
    
    // 受信データは [0, 65535] の範囲であるので [-1, 1] に変換する
    int offset = 32767;
    
    if ((iv[0] == offset) && (iv[1] == offset)) {
        return vector2f();
    }
    
    vector2f v;
    
    for (uint32_t i = 0; i < 2; ++i) {
        v[i] = iv[i];
        v[i] -= offset;
        v[i] /= offset;
        /*
        switch(iv[i]) {
            case 0:
                v[i] = 0.0f;
                break;
                
            case 1:
                v[i] = 1.0f;
                
                break;
                
            case 2:
                v[i] = -1.0f;
                break;
        }
        */
    }
    
    if (v.length() > 1.0f) {
        return ;
    }
    
    /*
    vector2f velocity = v.unit();
    return velocity;
    */
}
float communication::get_angular_velocity_rad_per_sec() const {
    return 0.0f;
}
communication::vector2f communication::get_target_position_mm() const {
    return vector2f();
}
float communication::get_target_heading_rad() const {
    return 0.0f;
}