Skip to content

Commit

Permalink
implemented programmable step length
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Coffland authored and jcoffland committed Jun 1, 2023
1 parent fdb8490 commit 0951758
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 53 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ BETA_PKG_NAME := bbctrl-$(BETA_VERSION)

SUBPROJECTS := avr boot pwr2 jig
SUBPROJECTS := $(patsubst %,src/%,$(SUBPROJECTS))
$(info SUBPROJECTS="$(SUBPROJECTS)")

WATCH := src/pug src/pug/templates src/stylus src/js src/resources Makefile
WATCH += src/static
Expand Down
2 changes: 1 addition & 1 deletion src/avr/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Makefile for the project Bulidbotics firmware
PROJECT = bbctrl-avr-firmware
MCU = atxmega192a3u
MCU = atxmega256a3u
CLOCK = 32000000

# SRC
Expand Down
2 changes: 1 addition & 1 deletion src/avr/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ enum {
#define STEP_TIMER_POLL ((uint16_t)(STEP_TIMER_FREQ * 0.001)) // 1ms
#define STEP_TIMER_ISR TCC0_OVF_vect
#define STEP_LOW_LEVEL_ISR ADCB_CH0_vect
#define STEP_PULSE_WIDTH (F_CPU * 0.000002) // 2uS w/ clk/1 .. modified to 10uS by doug
#define STEP_PULSE_WIDTH (F_CPU * 0.000002) // 2uS w/ clk/1
#define SEGMENT_MS 4
#define SEGMENT_TIME (SEGMENT_MS / 60000.0) // mins

Expand Down
10 changes: 10 additions & 0 deletions src/avr/src/motor.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ typedef struct {
uint16_t microsteps; // microsteps per full step
bool reverse;
bool enabled;
float pulse_length; // length of step pulses in microseconds
float step_angle; // degrees per whole step
float travel_rev; // mm or deg of travel per motor revolution
float min_soft_limit;
Expand Down Expand Up @@ -178,6 +179,15 @@ void motor_init() {
}


float get_pulse_length(int motor) {return motors[motor].pulse_length;}


void set_pulse_length(int motor, float value) {
motors[motor].pulse_length = value;
motors[motor].timer->CCA = value * F_CPU;
}


bool motor_is_enabled(int motor) {return motors[motor].enabled;}
int motor_get_axis(int motor) {return motors[motor].axis;}

Expand Down
2 changes: 1 addition & 1 deletion src/avr/src/oled.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,6 @@ void oled_splash() {
oled_init();
_writeStringAt((char *) "Controller booting",1,5);
_writeStringAt((char *) "Please wait...",3,5);
_writeStringAt((char *) "(c) Buildbotics LLC",4,5);
_writeStringAt((char *) "(c) Buildbotics LLC",5,5);
_delay_us(100);
};
1 change: 1 addition & 0 deletions src/avr/src/vars.def
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
VAR(motor_axis, an, u8, MOTORS, 1, 1) // Maps motor to axis

VAR(motor_enabled, me, b8, MOTORS, 1, 1) // Motor enabled
VAR(pulse_length, pl, f32, MOTORS, 1, 1) // length of step pulses
VAR(drive_current, dc, f32, MOTORS, 1, 1) // Max motor drive current
VAR(idle_current, ic, f32, MOTORS, 1, 1) // Motor idle current

Expand Down
4 changes: 2 additions & 2 deletions src/boot/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Makefile for the project Bulidbotics bootloader
PROJECT = bbctrl-avr-boot
MCU = atxmega192a3u
MCU = atxmega256a3u
CLOCK = 32000000

TARGET = $(PROJECT).elf
Expand All @@ -19,7 +19,7 @@ CFLAGS += -Isrc

# Linker flags
LDFLAGS += $(COMMON) -Wl,-u,vfprintf -lprintf_flt -lm
LDFLAGS += -Wl,--section-start=.text=0x030000
LDFLAGS += -Wl,--section-start=.text=0x040000
LIBS += -lm

# Programming flags
Expand Down
46 changes: 41 additions & 5 deletions src/js/settings-motor.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,17 @@ module.exports = {
},


maxStepsPerSecond: function () {return 250000},
maxStepsPerSecond: function () {return (0.5 / this.motor['step-length'])},


maxMaxVelocity: function () { // In meters per minute
let metersPerUStep = this.umPerStep / this.motor.microsteps / 1000000
return 1 * (this.maxStepsPerSec * 60 * metersPerUStep).toFixed(3)
maxMaxVelocity: function () {
let maxUStepsPerSecond = 0.5 / this.motor['step-length'];
let uStepsPerRevolution =
(360.0 / this.motor['step-angle']) * this.motor['microsteps'];
let maxRPS = maxUStepsPerSecond / uStepsPerRevolution;

return parseFloat((maxRPS * 60.0 * this.motor['travel-per-rev'] / 1000)
.toFixed(3)); // returns max vel in meters / minute
},


Expand Down Expand Up @@ -119,6 +124,10 @@ module.exports = {
events: {
'input-changed': function() {
Vue.nextTick(function () {
// set step length to default of 2ms if user selects internal drivers
if (this.motor['type-of-driver'] == 'internal')
this.$set('motor["step-length"]', 0.000002);

// Limit max-velocity
if (this.invalidMaxVelocity)
this.$set('motor["max-velocity"]', this.maxMaxVelocity);
Expand All @@ -127,6 +136,7 @@ module.exports = {
if (this.invalidStallVelocity)
this.$set('motor["search-velocity"]', this.maxStallVelocity);


this.$dispatch('config-changed');
}.bind(this))
return true;
Expand All @@ -136,8 +146,34 @@ module.exports = {

methods: {
show: function (name, templ) {
if (name == 'step-length' && this.motor['type-of-driver'] == 'internal')
return false;

if (this.motor['type-of-driver'] == 'generic external' &&
name == 'homing-mode') return false;

if (this.motor['type-of-driver'] == 'internal' &&
name == 'homing-mode-external') return false;

if ((this.motor['type-of-driver'] == 'generic external') &&
['stall-microstep', 'stall-volts', 'stall-sample-time',
'stall-current'].includes(name)) return false;

if (templ.hmodes == undefined) return true;
return templ.hmodes.indexOf(this.motor['homing-mode']) != -1;

if (this.motor['type-of-driver'] == 'internal')
return templ.hmodes.indexOf(this.motor['homing-mode']) != -1;

return templ.hmodes.indexOf(this.motor['homing-mode-external']) != -1;
},


showCategory: function (name) {
if (name == 'power' && this.motor['type-of-driver'] == 'generic external')
return false

return true;
}
}

}
2 changes: 1 addition & 1 deletion src/pug/templates/settings-motor.pug
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ script#settings-motor-template(type="text/x-template")
h1 Motor {{index}} Configuration

.pure-form.pure-form-aligned
fieldset(v-for="category in template.motors.template", :class="$key")
fieldset(v-for="category in template.motors.template", v-if='showCategory($key)', :class="$key")
h2 {{$key}}

templated-input(v-for="templ in category", v-if="show($key, templ)",
Expand Down
1 change: 0 additions & 1 deletion src/py/bbctrl/Comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ def connect(self):
try:
# Resume once current queue of GCode commands has flushed
self.queue_command(Cmd.RESUME)
self.queue_command(Cmd.set('ct', 128))
self.queue_command(Cmd.HELP) # Load AVR commands and variables

except Exception as e:
Expand Down
16 changes: 7 additions & 9 deletions src/py/bbctrl/LCD.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ def __init__(self, ctrl):
self.screen = self.new_screen()

try:
self.oled = OLED(self.ctrl)
except:
pass
self.oled = OLED(self.ctrl)
except: pass
self.wrote_to_oled = False

self.set_message('Loading...')

self._redraw(False)
Expand Down Expand Up @@ -122,12 +122,10 @@ def _redraw(self, now = True):
def _update(self):
self.timeout = None
try:
self.oled
self.oled.writePage(self.page.data)
self.wrote_to_oled = True
return
except:
self.wrote_to_oled = False
self.oled.writePage(self.page.data)
self.wrote_to_oled = True
return
except: pass

try:
if self.lcd is None:
Expand Down
Loading

0 comments on commit 0951758

Please sign in to comment.