|
|
@ -24,29 +24,35 @@ namespace simon { |
|
|
|
{ |
|
|
|
auto j_set = json::parse(read_file("settings.json")); |
|
|
|
a4988::a4988_settings_t a4988_set = {0}; |
|
|
|
if (!j_set["motors"].is_array()) { |
|
|
|
std::cout << "Expected an array in the configuration below \"motors\"." << "\n"; |
|
|
|
if (!j_set["axis_configurations"].is_array()) { |
|
|
|
std::cout << "Expected an array in the configuration below \"axis_configurations\"." << "\n"; |
|
|
|
// TODO: Throw exception
|
|
|
|
} |
|
|
|
int ind = 0; |
|
|
|
for (auto& motor : j_set["motors"]) { |
|
|
|
for (auto& j_axis_conf : j_set["axis_configurations"]) { |
|
|
|
ind++; |
|
|
|
if (motor["id"].is_string()) { |
|
|
|
if (motor["id"] == axis) { |
|
|
|
if (j_axis_conf["id"].is_string()) { |
|
|
|
if (j_axis_conf["id"] == axis) { |
|
|
|
a4988::a4988_settings_t a = { |
|
|
|
// TODO: Do more sanizing before retrieving this data
|
|
|
|
.gpio_en = motor["a4988"]["gpio_en"], |
|
|
|
.gpio_step = motor["a4988"]["gpio_step"], |
|
|
|
.gpio_dir = motor["a4988"]["gpio_dir"], |
|
|
|
.gpio_microsteps = motor["a4988"]["microsteps"] |
|
|
|
.gpio_en = j_axis_conf["a4988"]["gpio_en"], |
|
|
|
.gpio_step = j_axis_conf["a4988"]["gpio_step"], |
|
|
|
.gpio_dir = j_axis_conf["a4988"]["gpio_dir"], |
|
|
|
.gpio_microsteps = j_axis_conf["a4988"]["microsteps"] |
|
|
|
}; |
|
|
|
auto a_ptr = std::make_unique<a4988::a4988_settings_t>(a); |
|
|
|
m_ptr_a4988 = std::make_unique<a4988::c_allegro_4988>(std::move(a_ptr)); |
|
|
|
settings_t s = { |
|
|
|
// TODO: Do more sanizing before retrieving this data
|
|
|
|
.gear_reduction = j_axis_conf["stepper"]["gear_reduction"], |
|
|
|
.steps_per_revolution = j_axis_conf["stepper"]["steps_per_revolution"] |
|
|
|
}; |
|
|
|
m_stepper = s; |
|
|
|
break; |
|
|
|
} |
|
|
|
} else { |
|
|
|
// TODO:Throw exception
|
|
|
|
std::cerr << "Expected a string in the configuration below [\"motors\"][" << ind << "][\"id\"]\n"; |
|
|
|
std::cerr << "Expected a string in the configuration below [\"axis_configurations\"][" << ind << "][\"id\"]\n"; |
|
|
|
} |
|
|
|
} |
|
|
|
std::thread t1(std::bind(&a4988::c_allegro_4988::run, &(*m_ptr_a4988))); |
|
|
|