/*
 * global_variables.c
 *
 *　Variables that may be used in various places are defined here for the time being.
 *
 *  Created on: 2023/09/14
 */

/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2023 Takayoshi Uemitsu (BestTechnology CO.,LTD.)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

#include "global_variables.h"

//-----------------------------
// Interpolation data
//-----------------------------

// Interpolation 1D data for TAD2141 to deg
int32_t interp_tad2141_1d[] = {
    0, 1820, 3641, 5461, 7282, 9102,10923,12743,14563,16384,18204,20025,21845,23665,25486,27306,29127,30947,32768,34588,36408,38229,40049,41870,43690,45510,47331,49151,50972,52792,54613,56433,58253,60074,61894,63715,65535,  // x (raw value) [0..36]
    0, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000,10000,11000,12000,13000,14000,15000,16000,17000,18000,19000,20000,21000,22000,23000,24000,25000,26000,27000,28000,29000,30000,31000,32000,33000,34000,35000,35999   // y (degree * 100) [37..73]
};

// Interpolation 1D data for Angle compliance control
int32_t interp_angle_compliance_1d[] = {
    0, 0, 0, 0,         // x (err degx100)
    -1000, 0, 0, 1000,  // y (duty ‰)
};

// Interpolation 1D data for Current compliance control
int32_t interp_current_compliance_1d[] = {
    0, 0, 0, 0,         // x (err mA)
    -1000, 0, 0, 1000,  // y (duty ‰)
};

// Array Size
const int32_t interp_tad2141_ar_w = (sizeof (interp_tad2141_1d) / sizeof (interp_tad2141_1d[0])) / 2;
const int32_t interp_angle_compliance_ar_w = (sizeof (interp_angle_compliance_1d) / sizeof (interp_angle_compliance_1d[0])) / 2;
const int32_t interp_current_compliance_ar_w = (sizeof (interp_current_compliance_1d) / sizeof (interp_current_compliance_1d[0])) / 2;

//-----------------------------
// Control Gain
//-----------------------------
TPIDParam_real pidparam_ang =  { 1.6, 2.2, 0.004, 0, 0.001, -1000, 1000, {0,0},0 };
TPIDParam_real pidparam_velo = { 0.5, 3.2, 0.024, 0, 0.005, -1000, 1000, {0,0},0 };
TPIDParam_real pidparam_cur =  { 0.3, 5.0, 0.001, 0, 0.004, -1000, 1000, {0,0},0 };

bool UpdateTargetValue = false;
