improve oscilloscope functionality

This commit is contained in:
Oskar Weigl
2019-09-12 18:11:32 -07:00
parent 47bcdfa08f
commit 6a929d4236
5 changed files with 35 additions and 8 deletions
-5
View File
@@ -426,11 +426,6 @@ void vbus_sense_adc_cb(ADC_HandleTypeDef* hadc, bool injected) {
// Only one conversion in sequence, so only rank1
uint32_t ADCValue = HAL_ADCEx_InjectedGetValue(hadc, ADC_INJECTED_RANK_1);
vbus_voltage = ADCValue * voltage_scale;
if (axes[0] && !axes[0]->error_ && axes[1] && !axes[1]->error_) {
if (oscilloscope_pos >= OSCILLOSCOPE_SIZE)
oscilloscope_pos = 0;
oscilloscope[oscilloscope_pos++] = vbus_voltage;
}
}
static void decode_hall_samples(Encoder& enc, uint16_t GPIO_samples[num_GPIO]) {
+25
View File
@@ -410,6 +410,31 @@ bool Motor::FOC_current(float Id_des, float Iq_des, float I_phase, float pwm_pha
return false; // error set inside enqueue_modulation_timings
log_timing(TIMING_LOG_FOC_CURRENT);
if (axis_->axis_num_ == 0) {
// Edit these to suit your capture needs
float trigger_data = ictrl.v_current_control_integral_d;
float trigger_threshold = 0.5f;
float sample_data = Ialpha;
static bool ready = false;
static bool capturing = false;
if (trigger_data < trigger_threshold) {
ready = true;
}
if (ready && trigger_data >= trigger_threshold) {
capturing = true;
ready = false;
}
if (capturing) {
oscilloscope[oscilloscope_pos] = sample_data;
if (++oscilloscope_pos >= OSCILLOSCOPE_SIZE) {
oscilloscope_pos = 0;
capturing = false;
}
}
}
return true;
}
+1 -1
View File
@@ -94,7 +94,7 @@ constexpr size_t AXIS_COUNT = 2;
extern Axis *axes[AXIS_COUNT];
// if you use the oscilloscope feature you can bump up this value
#define OSCILLOSCOPE_SIZE 128
#define OSCILLOSCOPE_SIZE 4096
extern float oscilloscope[OSCILLOSCOPE_SIZE];
extern size_t oscilloscope_pos;
+3 -2
View File
@@ -5,7 +5,7 @@ import threading
import fibre
import odrive
import odrive.enums
from odrive.utils import start_liveplotter, dump_errors
from odrive.utils import start_liveplotter, dump_errors, oscilloscope_dump
#from odrive.enums import * # pylint: disable=W0614
def print_banner():
@@ -77,7 +77,8 @@ def launch_shell(args, logger, app_shutdown_token):
interactive_variables = {
'start_liveplotter': start_liveplotter,
'dump_errors': dump_errors
'dump_errors': dump_errors,
'oscilloscope_dump': oscilloscope_dump
}
# Expose all enums from odrive.enums
+6
View File
@@ -60,6 +60,12 @@ def dump_errors(odrv, clear=False):
else:
print(prefix + _VT100Colors['green'] + "no error" + _VT100Colors['default'])
def oscilloscope_dump(odrv, num_vals, filename='oscilloscope.csv'):
with open(filename, 'w') as f:
for x in range(num_vals):
f.write(str(odrv.get_oscilloscope_val(x)))
f.write('\n')
data_rate = 10
plot_rate = 10
num_samples = 1000