Browse Source

Introduced rotate function

feature/build_system
Maximilian Stiefel 3 years ago
parent
commit
ff5718125c
  1. 4
      drivers/a4988.cpp
  2. 20
      hal/stepper.cpp
  3. 1
      include/a4988.h
  4. 2
      include/stepper.h
  5. 3
      settings.json

4
drivers/a4988.cpp

@ -119,5 +119,9 @@ namespace simon {
m_pwm_freq = pwm_freq;
return 0;
}
unsigned c_allegro_4988::get_microsteps(void)
{
return m_ptr_set->gpio_microsteps;
}
} // namespace a4988
} // namespace simon

20
hal/stepper.cpp

@ -3,6 +3,8 @@
#include <functional>
#include <iostream>
#include <fstream>
#include <memory>
#include <cmath>
namespace simon {
namespace stepper {
@ -16,7 +18,8 @@ namespace simon {
}
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);
rotate(180);
rotate(-180);
m_ptr_a4988->kill();
m_thread.join();
}
@ -41,7 +44,8 @@ namespace simon {
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"]
.steps_per_revolution = j_axis_conf["stepper"]["steps_per_revolution"],
.clockwise = j_axis_conf["stepper"]["clockwise"]
};
break;
}
@ -66,5 +70,17 @@ namespace simon {
}
return jstring;
}
float c_stepper::rotate(const float& degrees)
{
auto steps_360 = m_stepper.gear_reduction
* m_stepper.steps_per_revolution
* static_cast<float>(m_ptr_a4988->get_microsteps());
auto steps = static_cast<unsigned>((std::abs(degrees)/360.0f) * steps_360);
bool direction = (degrees < 0) ? !m_stepper.clockwise : m_stepper.clockwise;
std::cout << "dir >" << direction << std::endl;
m_ptr_a4988->post_move(steps, direction, 100);
return steps;
}
}
}

1
include/a4988.h

@ -68,6 +68,7 @@ namespace simon {
void post_move(const unsigned steps, const bool dir,
const unsigned period_us);
void run(void);
unsigned get_microsteps(void);
private:
std::unique_ptr<a4988_settings_t> m_ptr_set;
bool m_initialized;

2
include/stepper.h

@ -13,12 +13,14 @@ namespace simon {
typedef struct {
float gear_reduction;
float steps_per_revolution;
bool clockwise;
} settings_t;
class c_stepper
{
public:
c_stepper(const std::string& axis);
float rotate(const float& degrees);
private:
settings_t m_stepper;
std::unique_ptr<a4988::c_allegro_4988> m_ptr_a4988;

3
settings.json

@ -3,7 +3,8 @@
{
"stepper": {
"gear_reduction": 64.0,
"steps_per_revolution": 32
"steps_per_revolution": 32,
"clockwise" : true
},
"a4988": {
"microsteps": 16,

Loading…
Cancel
Save