Simon's and Max' camera steering software. https://stiefel.tech
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

73 lines
2.1 KiB

#include <include/stepper.h>
#include <thread>
#include <functional>
#include <iostream>
#include <fstream>
namespace simon {
namespace stepper {
c_stepper::c_stepper(const std::string& axis)
/* : m_a4988
{
.gpio_en = 17,
.gpio_step = 18,
.gpio_dir = 22,
.gpio_microsteps{
true, true, true
},
m_stepper
{
.gear_reduction = 64.0f,
.steps_per_revolution = 32.0f
}
*/
{
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";
// TODO: Throw exception
}
int ind = 0;
for (auto& motor : j_set["motors"]) {
ind++;
if (motor["id"].is_string()) {
if (motor["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"]
};
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));
break;
}
} else {
// TODO:Throw exception
std::cerr << "Expected a string in the configuration below [\"motors\"][" << ind << "][\"id\"]\n";
}
}
std::thread t1(std::bind(&a4988::c_allegro_4988::run, &(*m_ptr_a4988)));
m_ptr_a4988->post_move(32768, true, 100);
m_ptr_a4988->kill();
t1.join();
}
std::string c_stepper::read_file(const std::string& fname) const
{
std::ifstream input_stream(fname);
if (!input_stream) {
// TODO: Throw exception here
std::cerr << "Can't open input file!";
}
std::string line;
std::string jstring;
while (getline(input_stream, line)) {
jstring += line;
}
return jstring;
}
}
}