```python
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from sympy import latex
from IPython.display import display, Math
plt.rcParams['figure.figsize'] = [20, 10]
```


```python
# retrived from https://www.arduino.cc/reference/en/language/functions/math/map/
def map_func(x, in_min, in_max, out_min, out_max):
    return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
```


```python
def adc2angle(df, shoulder_min=203, soulder_max=599, elbow_min=865, elbow_max=261, 
              shoulder_min_angle =-90, shoudler_max_angle=0, 
              elbow_min_angle=0, elbow_max_angle=145):
    col = df.columns # extract column names from dataframe
    
    # convertes first column (shoulder) to angles between -90 and 0
    df[col[0]] = df.apply(lambda x: map_func(df[col[0]], shoulder_min, soulder_max, shoulder_min_angle, shoudler_max_angle)) 
    
    # convertes second column (elbow) to angles between 0 and 160
    df[col[1]] = df.apply(lambda x: map_func(df[col[1]], elbow_min, elbow_max, elbow_min_angle, elbow_max_angle))
    return df
```

# Mapping Calibration


```python
df = pd.read_csv('./datasets/pot_cal_dataset_clean_1.csv') # dataset generated during calibration run
df # prints pot ADC values
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Shoulder</th>
      <th>Elbow</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>203.0</td>
      <td>490.0</td>
    </tr>
    <tr>
      <th>1</th>
      <td>203.0</td>
      <td>490.0</td>
    </tr>
    <tr>
      <th>2</th>
      <td>198.0</td>
      <td>489.0</td>
    </tr>
    <tr>
      <th>3</th>
      <td>202.0</td>
      <td>865.0</td>
    </tr>
    <tr>
      <th>4</th>
      <td>599.0</td>
      <td>491.0</td>
    </tr>
    <tr>
      <th>5</th>
      <td>598.0</td>
      <td>490.0</td>
    </tr>
    <tr>
      <th>6</th>
      <td>598.0</td>
      <td>489.0</td>
    </tr>
  </tbody>
</table>
</div>



- shoulder
    - min
        - angle:-90
        - ADC: 203
        
    - max
        - angle: 0
        - ADC: 599

- elbow
    - min
        - angle: 0
        - ADC: 865
    - max
        - angle: 90
            - extrapolated angle: 145
        - ADC: 490
            - extrapolated ADC: 261


```python
m = (865 - 490)/(0 - 90)

y_145 = m*145 + 865
y_145
```




    260.83333333333326




```python
# df['Shoulder'] = df.apply(lambda x: map_func(df['Shoulder'], 203, 599, -90, 0))
# df['Elbow'] = df.apply(lambda x: map_func(df['Elbow'], 865, 261, 0, 145))

df = adc2angle(df)
df # prints pot converted angle values
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Shoulder</th>
      <th>Elbow</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>-90.000000</td>
      <td>90.024834</td>
    </tr>
    <tr>
      <th>1</th>
      <td>-90.000000</td>
      <td>90.024834</td>
    </tr>
    <tr>
      <th>2</th>
      <td>-91.136364</td>
      <td>90.264901</td>
    </tr>
    <tr>
      <th>3</th>
      <td>-90.227273</td>
      <td>0.000000</td>
    </tr>
    <tr>
      <th>4</th>
      <td>0.000000</td>
      <td>89.784768</td>
    </tr>
    <tr>
      <th>5</th>
      <td>-0.227273</td>
      <td>90.024834</td>
    </tr>
    <tr>
      <th>6</th>
      <td>-0.227273</td>
      <td>90.264901</td>
    </tr>
  </tbody>
</table>
</div>



# Converting ADC Values of Traced Image to Angles


```python
df = pd.read_csv('./datasets/hyster_dataset_clean_1.csv') # second_trial_3.csv is the results of the traced image
df = df.dropna()
df = adc2angle(df)
df.to_csv('angles_1.csv', index=False)
```


```python
df = pd.read_csv('./datasets/hyster_dataset_clean_5.csv') # second_trial_3.csv is the results of the traced image
df = df.dropna()
df = adc2angle(df)
df.to_csv('angles_5.csv', index=False)
```

ipynb
217970b56ae26903a057c653e7260e77280a7f73
Jupyter Notebook
2022-03-20T15:32:27.000Z
2022-03-20T15:32:27.000Z
987d19deacc8cb36c473adf33335fc63ae4aab10
MIT
cplan082-tech/project_csi4103
deliverables/del_e/pot_calibration/pot_calibration.ipynb
987d19deacc8cb36c473adf33335fc63ae4aab10
MIT
cplan082-tech/project_csi4103
deliverables/del_e/pot_calibration/pot_calibration.ipynb
987d19deacc8cb36c473adf33335fc63ae4aab10
MIT
cplan082-tech/project_csi4103
deliverables/del_e/pot_calibration/pot_calibration.ipynb
2022-03-22T21:23:12.000Z
2022-03-20T21:38:28.000Z