Skip to content

Commit

Permalink
Getting this branch to compile for gShield - inlcudes example VSCode …
Browse files Browse the repository at this point in the history
…target and laser support
  • Loading branch information
giseburt committed Apr 13, 2020
1 parent 1a39660 commit 404106b
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 35 deletions.
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@
},
"preLaunchTask": "Build CONFIG=r7 Debug"
},
{
"name": "Debug CONFIG=MiniMillgShield (J-Link)",
"type": "cortex-debug",
"request": "launch",
"servertype": "jlink",
"cwd": "${workspaceRoot}/g2core/",
"executable": "./bin/MiniMillgShield-gShield/g2core.elf",
"device": "ATSAMS3X8E",
"svdFile": "${workspaceRoot}/Motate/MotateProject/motate/cmsis/TARGET_Atmel/sam3x/ATSAM3X8E.svd",
"interface": "swd",
"showDevDebugOutput": false,
"osx": {
"armToolchainPath": "${workspaceRoot}/Motate/Tools/osx/gcc-arm-none-eabi-7u2/bin/"
},
"linux": {
"armToolchainPath": "${workspaceRoot}/Motate/Tools/linux/gcc-arm-none-eabi-9m/bin/"
},
"preLaunchTask": "Build CONFIG=MiniMillgShield Debug"
},
{
"name": "Debug CONFIG=ShapeokoDualY (J-Link)",
"type": "cortex-debug",
Expand Down
35 changes: 35 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,41 @@
"fileLocation": ["relative", "${workspaceRoot}/g2core"]
}
},
{
"label": "Build CONFIG=MiniMillgShield Debug",
"type": "process",
"command": "make",
"args": ["CONFIG=MiniMillgShield", "VERBOSE=2", "COLOR=0", "DEBUG=2",
"RECORD=1"],
"group": "build",
"problemMatcher": {
"base": "$gcc",
"fileLocation": ["relative", "${workspaceRoot}/g2core"]
}
},
{
"label": "Build CONFIG=MiniMillgShield Production",
"type": "process",
"command": "make",
"args": ["CONFIG=MiniMillgShield", "VERBOSE=2", "COLOR=0",
"RECORD=1"],
"group": "build",
"problemMatcher": {
"base": "$gcc",
"fileLocation": ["relative", "${workspaceRoot}/g2core"]
}
},
{
"label": "Clean CONFIG=MiniMillgShield",
"type": "process",
"command": "make",
"args": ["CONFIG=MiniMillgShield", "clean"],
"group": "build",
"problemMatcher": {
"base": "$gcc",
"fileLocation": ["relative", "${workspaceRoot}/g2core"]
}
},
{
"label": "Build CONFIG=MiniMillv9 Debug",
"type": "process",
Expand Down
2 changes: 1 addition & 1 deletion g2core/board/ArduinoDue.mk
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ifeq ("$(BASE_BOARD)","g2core-due")
# Note: we call it "g2core-due" instead of "due" since the Motate built-in provides
# a "due" BASE_BOARD.
BOARD_PATH = ./board/ArduinoDue
SOURCE_DIRS += ${BOARD_PATH} device/step_dir_driver device/esc_spindle
SOURCE_DIRS += ${BOARD_PATH} device/step_dir_driver device/esc_spindle device/laser_toolhead

PLATFORM_BASE = ${MOTATE_PATH}/platform/atmel_sam

Expand Down
110 changes: 103 additions & 7 deletions g2core/board/ArduinoDue/0_hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,35 @@
SafetyManager sm{};
SafetyManager *safety_manager = &sm;

// Stub in getSysConfig_3
// constexpr cfgItem_t sys_config_items_3[] = {};
constexpr cfgSubtableFromStaticArray sys_config_3{};
const configSubtable * const getSysConfig_3() { return &sys_config_3; }

#include "esc_spindle.h"
ESCSpindle esc_spindle {SPINDLE_PWM_NUMBER, SPINDLE_ENABLE_OUTPUT_NUMBER, SPINDLE_DIRECTION_OUTPUT_NUMBER, SPINDLE_SPEED_CHANGE_PER_MS};

#if HAS_LASER
#ifndef LASER_ENABLE_OUTPUT_NUMBER
#error LASER_ENABLE_OUTPUT_NUMBER should be defined in settings or a board file!
#endif

#ifndef LASER_FIRE_PIN_NUMBER
#error LASER_FIRE_PIN_NUMBER should be defined in settings or a board file!
#endif

#include "laser_toolhead.h"
LaserTool_used_t laser_tool {LASER_ENABLE_OUTPUT_NUMBER, MOTOR_5};

// CartesianKinematics<AXES, MOTORS> cartesian_kinematics;
KinematicsBase<AXES, MOTORS> *kn = &laser_tool;
#endif

ToolHead *toolhead_for_tool(uint8_t tool) {
#if !HAS_LASER
return &esc_spindle;
#else
if (tool != LASER_TOOL) {
return &esc_spindle;
} else {
return &laser_tool;
}
#endif
}

/*
Expand All @@ -82,8 +101,13 @@ ToolHead *toolhead_for_tool(uint8_t tool) {
void hardware_init()
{
board_hardware_init();
toolhead_for_tool(0)->init();
spindle_set_toolhead(toolhead_for_tool(0));

esc_spindle.init();
#if HAS_LASER
laser_tool.init();
#endif
spindle_set_toolhead(toolhead_for_tool(1));

return;
}

Expand Down Expand Up @@ -190,6 +214,78 @@ stat_t hw_flash(nvObj_t *nv)
return(STAT_OK);
}

#if !HAS_LASER
// Stub in getSysConfig_3
// constexpr cfgItem_t sys_config_items_3[] = {};
constexpr cfgSubtableFromStaticArray sys_config_3{};
const configSubtable * const getSysConfig_3() { return &sys_config_3; }

#else

stat_t set_pulse_duration(nvObj_t *nv)
{
laser_tool.set_pulse_duration_us(nv->valuetype == TYPE_FLOAT ? nv->value_flt : nv->value_int);
return (STAT_OK);
}
stat_t get_pulse_duration(nvObj_t *nv)
{
nv->value_int = laser_tool.get_pulse_duration_us();
nv->valuetype = TYPE_INTEGER;
return (STAT_OK);
}

stat_t get_min_s(nvObj_t *nv) {
nv->value_flt = laser_tool.get_min_s();
nv->valuetype = TYPE_FLOAT;
return (STAT_OK);
}
stat_t set_min_s(nvObj_t *nv) {
laser_tool.set_min_s(nv->value_flt);
return (STAT_OK);
}

stat_t get_max_s(nvObj_t *nv) {
nv->value_flt = laser_tool.get_max_s();
nv->valuetype = TYPE_FLOAT;
return (STAT_OK);
}
stat_t set_max_s(nvObj_t *nv) {
laser_tool.set_max_s(nv->value_flt);
return (STAT_OK);
}

stat_t get_min_ppm(nvObj_t *nv) {
nv->value_flt = laser_tool.get_min_ppm();
nv->valuetype = TYPE_FLOAT;
return (STAT_OK);
}
stat_t set_min_ppm(nvObj_t *nv) {
laser_tool.set_min_ppm(nv->value_flt);
return (STAT_OK);
}

stat_t get_max_ppm(nvObj_t *nv) {
nv->value_flt = laser_tool.get_max_ppm();
nv->valuetype = TYPE_FLOAT;
return (STAT_OK);
}
stat_t set_max_ppm(nvObj_t *nv) {
laser_tool.set_max_ppm(nv->value_flt);
return (STAT_OK);
}

constexpr cfgItem_t sys_config_items_3[] = {
{ "th2","th2pd", _iip, 0, tx_print_nul, get_pulse_duration, set_pulse_duration, nullptr, LASER_PULSE_DURATION },
{ "th2","th2mns", _fip, 0, tx_print_nul, get_min_s, set_min_s, nullptr, LASER_MIN_S },
{ "th2","th2mxs", _fip, 0, tx_print_nul, get_max_s, set_max_s, nullptr, LASER_MAX_S },
{ "th2","th2mnp", _fip, 0, tx_print_nul, get_min_ppm, set_min_ppm, nullptr, LASER_MIN_PPM },
{ "th2","th2mxp", _fip, 0, tx_print_nul, get_max_ppm, set_max_ppm, nullptr, LASER_MAX_PPM },
};

constexpr cfgSubtableFromStaticArray sys_config_3{sys_config_items_3};
const configSubtable * const getSysConfig_3() { return &sys_config_3; }

#endif

/***********************************************************************************
* TEXT MODE SUPPORT
Expand Down
12 changes: 6 additions & 6 deletions g2core/board/ArduinoDue/board_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
#define INPUT_LOCKOUT_MS 10 // milliseconds to go dead after input firing

// Setup spindle and coolant pin assignments
#define SPINDLE_ENABLE_OUTPUT_NUMBER 1
#define SPINDLE_DIRECTION_OUTPUT_NUMBER 2
#define SPINDLE_PWM_NUMBER 3
#define MIST_ENABLE_OUTPUT_NUMBER 4
// #define SPINDLE_ENABLE_OUTPUT_NUMBER 1
// #define SPINDLE_DIRECTION_OUTPUT_NUMBER 2
// #define SPINDLE_PWM_NUMBER 3
// #define MIST_ENABLE_OUTPUT_NUMBER 4

#define FLOOD_ENABLE_OUTPUT_NUMBER 0
#define SECONDARY_PWM_OUTPUT_NUMBER 0
// #define FLOOD_ENABLE_OUTPUT_NUMBER 0
// #define SECONDARY_PWM_OUTPUT_NUMBER 0

/*
* The GPIO objects themselves - this must match up with board_gpio.cpp!
Expand Down
10 changes: 9 additions & 1 deletion g2core/board/ArduinoDue/board_stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,15 @@ StepDirStepper<Motate::kSocket4_StepPinNumber,
// Motate::kSocket6_VrefPinNumber>
// motor_6 {M6_STEP_POLARITY, M6_ENABLE_POLARITY};

Stepper* Motors[MOTORS] = {&motor_1, &motor_2, &motor_3, &motor_4};
#if HAS_LASER
// laser_tool is defined over in hardware.cpp
extern LaserTool_used_t laser_tool;
LaserTool_used_t &motor_5 = laser_tool;
Stepper* const Motors[MOTORS] = {&motor_1, &motor_2, &motor_3, &motor_4, &motor_5};
#else
Stepper* const Motors[MOTORS] = {&motor_1, &motor_2, &motor_3, &motor_4};
#endif


void board_stepper_init() {
for (uint8_t motor = 0; motor < MOTORS; motor++) { Motors[motor]->init(); }
Expand Down
11 changes: 9 additions & 2 deletions g2core/board/ArduinoDue/board_stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,15 @@ extern StepDirStepper<Motate::kSocket4_StepPinNumber,
// Motate::kSocket6_Microstep_2PinNumber,
// Motate::kSocket6_VrefPinNumber> motor_6 {};

extern Stepper* Motors[MOTORS];
#if HAS_LASER
#include "laser_toolhead.h"
#include "kinematics_cartesian.h"
typedef LaserTool<BASE_KINEMATICS, LASER_FIRE_PIN_NUMBER> LaserTool_used_t;
extern LaserTool_used_t &motor_5;
#endif

extern Stepper* const Motors[MOTORS];

void board_stepper_init();

#endif // BOARD_STEPPER_H_ONCE
#endif // BOARD_STEPPER_H_ONCE
14 changes: 14 additions & 0 deletions g2core/board/ArduinoDue/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
*/

#include "config.h"
#include "settings.h"
#include "error.h"

#include "MotateUtilities.h" // for HOT_FUNC and HOT_DATA

#ifndef HARDWARE_H_ONCE
#define HARDWARE_H_ONCE

Expand All @@ -40,11 +43,22 @@
#define G2CORE_HARDWARE_PLATFORM "ArduinoDue"
#define G2CORE_HARDWARE_VERSION "na"

#ifndef HAS_LASER
#if HAS_HOBBY_SERVO_MOTOR
#error Can NOT have a laser and a hobby servo at the same time, sorry
#endif
#define HAS_LASER 0
#endif

/***** Motors & PWM channels supported by this hardware *****/
// These must be defines (not enums) so expressions like this:
// #if (MOTORS >= 6) will work

#if HAS_LASER
#define MOTORS 5 // number of motors + one "laser" motor (used for pulsing the laser in sync)
#else
#define MOTORS 4 // number of motors supported the hardware
#endif
#define PWMS 2 // number of PWM channels supported the hardware
#define AXES 6 // axes to support -- must be 6 or 9

Expand Down
2 changes: 1 addition & 1 deletion g2core/board/gquintic.mk
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ifeq ("$(BASE_BOARD)","gquintic")
endif

BOARD_PATH = ./board/gquintic
SOURCE_DIRS += ${BOARD_PATH} device/trinamic device/step_dir_hobbyservo device/max31865 device/i2c_eeprom device/i2c_multiplexer device/i2c_as5601 device/esc_spindle device/laser_toolhead
SOURCE_DIRS += ${BOARD_PATH} device/trinamic device/step_dir_hobbyservo device/max31865 device/i2c_eeprom device/i2c_multiplexer device/i2c_as5601 device/esc_spindle device/laser_toolhead

PLATFORM_BASE = ${MOTATE_PATH}/platform/atmel_sam
include $(PLATFORM_BASE).mk
Expand Down
2 changes: 1 addition & 1 deletion g2core/board/gquintic/board_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#define BOARD_GPIO_H_ONCE

// this file is included from the bottom of gpio.h, but we do this for completeness
#include "../../gpio.h"
#include "gpio.h"
#include "hardware.h"

/*
Expand Down
1 change: 0 additions & 1 deletion g2core/board/gquintic/board_stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ Stepper* const Motors[MOTORS] = {&motor_1, &motor_2, &motor_3, &motor_4, &motor_
extern LaserTool_used_t laser_tool;
LaserTool_used_t &motor_6 = laser_tool;
Stepper* const Motors[MOTORS] = {&motor_1, &motor_2, &motor_3, &motor_4, &motor_5, &motor_6};
#warning here
#else
Stepper* const Motors[MOTORS] = {&motor_1, &motor_2, &motor_3, &motor_4, &motor_5};
#endif
Expand Down
7 changes: 6 additions & 1 deletion g2core/boards.mk
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,19 @@ ifeq ("$(CONFIG)","MiniMillrevD")
SETTINGS_FILE="settings_minimill.h"
endif


ifeq ("$(CONFIG)","MiniMill")
ifeq ("$(BOARD)","NONE")
BOARD=gquintic-g
endif
SETTINGS_FILE="settings_minimill.h"
endif

ifeq ("$(CONFIG)","MiniMillgShield")
ifeq ("$(BOARD)","NONE")
BOARD=gShield
endif
SETTINGS_FILE="settings_minimill.h"
endif

ifeq ("$(CONFIG)","CheapoLaser")
ifeq ("$(BOARD)","NONE")
Expand Down
14 changes: 0 additions & 14 deletions g2core/plan_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,26 +437,12 @@ static mpBuf_t* _plan_block(mpBuf_t* bf)
}

/***** ALINE HELPERS *****
* _calculate_override() - calculate cruise_vmax given cruise_vset and feed rate factor
* _calculate_jerk()
* _calculate_vmaxes()
* _calculate_junction_vmax()
* _calculate_decel_time()
*/

static void _calculate_override(mpBuf_t* bf) // execute ramp to adjust cruise velocity
{
if (bf->gm.motion_mode == MOTION_MODE_STRAIGHT_TRAVERSE) {
bf->override_factor = cm->gmx.mto_enable ? cm->gmx.mto_factor : 1.0;
}

else if (bf->gm.motion_mode == MOTION_MODE_STRAIGHT_FEED) {
bf->override_factor = cm->gmx.mfo_enable ? cm->gmx.mfo_factor : 1.0;
}

bf->cruise_vmax = std::min(bf->absolute_vmax, bf->override_factor * bf->cruise_vset);
}

/****************************************************************************************
* _calculate_jerk() - calculate jerk given the dynamic state
*
Expand Down

0 comments on commit 404106b

Please sign in to comment.