diff --git a/hal/stepper.cpp b/hal/stepper.cpp index d170204..c717d35 100644 --- a/hal/stepper.cpp +++ b/hal/stepper.cpp @@ -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(a); m_ptr_a4988 = std::make_unique(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))); diff --git a/settings.json b/settings.json index f8f2e71..7efe52e 100644 --- a/settings.json +++ b/settings.json @@ -1,5 +1,5 @@ { - "motors": [ + "axis_configurations": [ { "stepper": { "gear_reduction": 64.0,