| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -7,47 +7,42 @@ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					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}; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      auto file_content = read_file("settings.json"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      auto j_set = json::parse(file_content); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      if (!j_set["axis_configurations"].is_array()) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        std::cout << "Expected an array in the configuration below \"axis_configurations\"." << "\n"; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        // TODO: Throw exception
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      extract_settings(j_set, axis); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      m_thread = std::thread(std::bind(&a4988::c_allegro_4988::run, &(*m_ptr_a4988))); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      m_ptr_a4988->post_move(32768, true, 100); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      m_ptr_a4988->kill(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      m_thread.join(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    void c_stepper::extract_settings(const json& j_set, const std::string& axis) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      int ind = 0; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      for (auto& j_axis_conf : j_set["axis_configurations"]) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      for (const auto& j_axis_conf : j_set["axis_configurations"]) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        ind++; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        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 = 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); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            auto a_ptr = std::make_unique<a4988::a4988_settings_t>( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					              a4988::a4988_settings_t ({ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                // TODO: Do more sanitizing before retrieving this data
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                .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"] | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					              }) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            ); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            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
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            m_stepper = { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					               // TODO: Do more sanitizing 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 { | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -55,10 +50,6 @@ namespace simon { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          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))); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      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 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |