Skip to content

Commit 569814f

Browse files
Doug Cofflandjcoffland
Doug Coffland
authored andcommitted
implemented programmable step length
1 parent fdb8490 commit 569814f

File tree

13 files changed

+256
-53
lines changed

13 files changed

+256
-53
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ BETA_PKG_NAME := bbctrl-$(BETA_VERSION)
2828

2929
SUBPROJECTS := avr boot pwr2 jig
3030
SUBPROJECTS := $(patsubst %,src/%,$(SUBPROJECTS))
31+
$(info SUBPROJECTS="$(SUBPROJECTS)")
3132

3233
WATCH := src/pug src/pug/templates src/stylus src/js src/resources Makefile
3334
WATCH += src/static

src/avr/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Makefile for the project Bulidbotics firmware
22
PROJECT = bbctrl-avr-firmware
3-
MCU = atxmega192a3u
3+
MCU = atxmega256a3u
44
CLOCK = 32000000
55

66
# SRC

src/avr/src/config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ enum {
142142
#define STEP_TIMER_POLL ((uint16_t)(STEP_TIMER_FREQ * 0.001)) // 1ms
143143
#define STEP_TIMER_ISR TCC0_OVF_vect
144144
#define STEP_LOW_LEVEL_ISR ADCB_CH0_vect
145-
#define STEP_PULSE_WIDTH (F_CPU * 0.000002) // 2uS w/ clk/1 .. modified to 10uS by doug
145+
#define STEP_PULSE_WIDTH (F_CPU * 0.000002) // 2uS w/ clk/1
146146
#define SEGMENT_MS 4
147147
#define SEGMENT_TIME (SEGMENT_MS / 60000.0) // mins
148148

src/avr/src/motor.c

+10
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ typedef struct {
6060
uint16_t microsteps; // microsteps per full step
6161
bool reverse;
6262
bool enabled;
63+
float pulse_length; // length of step pulses in microseconds
6364
float step_angle; // degrees per whole step
6465
float travel_rev; // mm or deg of travel per motor revolution
6566
float min_soft_limit;
@@ -178,6 +179,15 @@ void motor_init() {
178179
}
179180

180181

182+
float get_pulse_length(int motor) {return 1.0 * (motors[motor].pulse_length);}
183+
184+
185+
void set_pulse_length(int motor, float value) {
186+
motors[motor].pulse_length = value;
187+
motors[motor].timer->CCA = value * F_CPU;
188+
}
189+
190+
181191
bool motor_is_enabled(int motor) {return motors[motor].enabled;}
182192
int motor_get_axis(int motor) {return motors[motor].axis;}
183193

src/avr/src/oled.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,6 @@ void oled_splash() {
139139
oled_init();
140140
_writeStringAt((char *) "Controller booting",1,5);
141141
_writeStringAt((char *) "Please wait...",3,5);
142-
_writeStringAt((char *) "(c) Buildbotics LLC",4,5);
142+
_writeStringAt((char *) "(c) Buildbotics LLC",5,5);
143143
_delay_us(100);
144144
};

src/avr/src/vars.def

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
VAR(motor_axis, an, u8, MOTORS, 1, 1) // Maps motor to axis
4040

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

src/boot/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Makefile for the project Bulidbotics bootloader
22
PROJECT = bbctrl-avr-boot
3-
MCU = atxmega192a3u
3+
MCU = atxmega256a3u
44
CLOCK = 32000000
55

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

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

2525
# Programming flags

src/js/settings-motor.js

+41-5
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,17 @@ module.exports = {
5454
},
5555

5656

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

5959

60-
maxMaxVelocity: function () { // In meters per minute
61-
let metersPerUStep = this.umPerStep / this.motor.microsteps / 1000000
62-
return 1 * (this.maxStepsPerSec * 60 * metersPerUStep).toFixed(3)
60+
maxMaxVelocity: function () {
61+
let maxUStepsPerSecond = 0.5 / this.motor['step-length'];
62+
let uStepsPerRevolution =
63+
(360.0 / this.motor['step-angle']) * this.motor['microsteps'];
64+
let maxRPS = maxUStepsPerSecond / uStepsPerRevolution;
65+
66+
return parseFloat((maxRPS * 60.0 * this.motor['travel-per-rev'] / 1000)
67+
.toFixed(3)); // returns max vel in meters / minute
6368
},
6469

6570

@@ -119,6 +124,10 @@ module.exports = {
119124
events: {
120125
'input-changed': function() {
121126
Vue.nextTick(function () {
127+
// set step length to default of 2ms if user selects internal drivers
128+
if (this.motor['type-of-driver'] == 'internal')
129+
this.$set('motor["step-length"]', 0.000002);
130+
122131
// Limit max-velocity
123132
if (this.invalidMaxVelocity)
124133
this.$set('motor["max-velocity"]', this.maxMaxVelocity);
@@ -127,6 +136,7 @@ module.exports = {
127136
if (this.invalidStallVelocity)
128137
this.$set('motor["search-velocity"]', this.maxStallVelocity);
129138

139+
130140
this.$dispatch('config-changed');
131141
}.bind(this))
132142
return true;
@@ -136,8 +146,34 @@ module.exports = {
136146

137147
methods: {
138148
show: function (name, templ) {
149+
if (name == 'step-length' && this.motor['type-of-driver'] == 'internal')
150+
return false;
151+
152+
if (this.motor['type-of-driver'] == 'generic external' &&
153+
name == 'homing-mode') return false;
154+
155+
if (this.motor['type-of-driver'] == 'internal' &&
156+
name == 'homing-mode-external') return false;
157+
158+
if ((this.motor['type-of-driver'] == 'generic external') &&
159+
['stall-microstep', 'stall-volts', 'stall-sample-time',
160+
'stall-current'].includes(name)) return false;
161+
139162
if (templ.hmodes == undefined) return true;
140-
return templ.hmodes.indexOf(this.motor['homing-mode']) != -1;
163+
164+
if (this.motor['type-of-driver'] == 'internal')
165+
return templ.hmodes.indexOf(this.motor['homing-mode']) != -1;
166+
167+
return templ.hmodes.indexOf(this.motor['homing-mode-external']) != -1;
168+
},
169+
170+
171+
showCategory: function (name) {
172+
if (name == 'power' && this.motor['type-of-driver'] == 'generic external')
173+
return false
174+
175+
return true;
141176
}
142177
}
178+
143179
}

src/pug/templates/settings-motor.pug

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ script#settings-motor-template(type="text/x-template")
3030
h1 Motor {{index}} Configuration
3131

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

3636
templated-input(v-for="templ in category", v-if="show($key, templ)",

src/py/bbctrl/Comm.py

-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ def connect(self):
265265
try:
266266
# Resume once current queue of GCode commands has flushed
267267
self.queue_command(Cmd.RESUME)
268-
self.queue_command(Cmd.set('ct', 128))
269268
self.queue_command(Cmd.HELP) # Load AVR commands and variables
270269

271270
except Exception as e:

src/py/bbctrl/LCD.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ def __init__(self, ctrl):
5454
self.screen = self.new_screen()
5555

5656
try:
57-
self.oled = OLED(self.ctrl)
58-
except:
59-
pass
57+
self.oled = OLED(self.ctrl)
58+
except: pass
6059
self.wrote_to_oled = False
60+
6161
self.set_message('Loading...')
6262

6363
self._redraw(False)
@@ -122,12 +122,10 @@ def _redraw(self, now = True):
122122
def _update(self):
123123
self.timeout = None
124124
try:
125-
self.oled
126-
self.oled.writePage(self.page.data)
127-
self.wrote_to_oled = True
128-
return
129-
except:
130-
self.wrote_to_oled = False
125+
self.oled.writePage(self.page.data)
126+
self.wrote_to_oled = True
127+
return
128+
except: pass
131129

132130
try:
133131
if self.lcd is None:

0 commit comments

Comments
 (0)