Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ script:
- bash -x test.sh
- bash -x build.sh
- wget https://github.com/prusa3d/caterina/releases/download/V4/Caterina-prusa_mm_control.hex
- srec_cat ../MM-control-01-build/MM-control-01.hex.tmp -Intel Caterina-prusa_mm_control.hex -Intel -Output MM-control-01_with_bootloader.hex -Intel
- srec_cat ../MM-control-01-build/MM-control-01.hex.tmp -Intel Caterina-prusa_mm_control.hex -Intel -Output MM-control-01_MMUv2_with_bootloader.hex -Intel
- mv Doxyfile MM-control-01/Doxyfile && cd MM-control-01
- doxygen && cd ..
deploy:
provider: releases
api_key: $ACCESS_TOKEN
file:
- ../MM-control-01-build/MM-control-01.hex
- MM-control-01_with_bootloader.hex
- ../MM-control-01-build/MM-control-01_MMUv2.hex
- ../MM-control-01_FANTAv1-build/MM-control-01_FANTAv1.hex
- MM-control-01_MMUv2_with_bootloader.hex
skip_cleanup: true
on:
tags: true
62 changes: 47 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.3)

#
# Command Line Options
#
# You should specify those options when invoking CMake. Example:
# ~~~
# cmake .. <other options> -DMODEL=FANTAv1
# ~~~

SET(MODEL_VALID_OPTS "MMUv2" "FANTAv1")

SET(MODEL
"MMUv2"
CACHE
STRING
"Select the model for which you want to compile the project (valid values are ${MODEL_VALID_OPTS})."
)

# Validate options
foreach(OPTION "MODEL")
if(NOT ${OPTION} IN_LIST ${OPTION}_VALID_OPTS)
message(FATAL_ERROR "Invalid ${OPTION} ${${OPTION}}: Valid values are ${${OPTION}_VALID_OPTS}")
endif()
endforeach()


SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_C_COMPILER avr-gcc)
Expand Down Expand Up @@ -44,9 +69,16 @@ git_count_parent_commits(GIT_PARENT_COMMITS)
git_local_changes(GIT_LOCAL_CHANGES)

configure_file(
${CMAKE_SOURCE_DIR}/MM-control-01/version.h.in
version.h
${CMAKE_SOURCE_DIR}/MM-control-01/version.h.in
version.h
)

configure_file(
${CMAKE_SOURCE_DIR}/MM-control-01/configuration_${MODEL}.h.in
configuration.h
COPYONLY
)

# The 'real' git information file
set(GITREV_BARE_FILE dirty.h)
# The temporary git information file
Expand Down Expand Up @@ -103,7 +135,7 @@ add_custom_command(
COMMAND ${CAT}
ARGS ${CMAKE_SOURCE_DIR}/MM-control-01.hex.in
MM-control-01.hex.tmp
> MM-control-01.hex
> MM-control-01_${MODEL}.hex
COMMENT "Generating HEX image"
VERBATIM
)
Expand All @@ -126,18 +158,18 @@ add_custom_target(


add_custom_command(
OUTPUT ${GITREV_TMP}
COMMAND ${CMAKE_COMMAND} -E echo_append "#define FW_LOCAL_CHANGES " > ${GITREV_TMP}
COMMAND ${GIT_EXECUTABLE} diff-index --quiet HEAD -- && echo 0 >> ${GITREV_TMP} || echo 1 >> ${GITREV_TMP}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GITREV_TMP} ${GITREV_FILE}
COMMAND ${CMAKE_COMMAND} -E remove ${GITREV_TMP}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
VERBATIM
OUTPUT ${GITREV_TMP}
COMMAND ${CMAKE_COMMAND} -E echo_append "#define FW_LOCAL_CHANGES " > ${GITREV_TMP}
COMMAND ${GIT_EXECUTABLE} diff-index --quiet HEAD -- && echo 0 >> ${GITREV_TMP} || echo 1 >> ${GITREV_TMP}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GITREV_TMP} ${GITREV_FILE}
COMMAND ${CMAKE_COMMAND} -E remove ${GITREV_TMP}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
VERBATIM
)

if ("Windows" STREQUAL CMAKE_HOST_SYSTEM_NAME)
configure_file(
${CMAKE_SOURCE_DIR}/build.bat.in
build.bat
)
configure_file(
${CMAKE_SOURCE_DIR}/build.bat.in
build.bat
)
endif()
21 changes: 21 additions & 0 deletions MM-control-01/configuration_FANTAv1.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! @file
//! @author Marek Bel

#ifndef CONFIGURATION_H
#define CONFIGURATION_H

// FANTAv1 configuration
// edit input file configuration_FANTAv1.h.in

static constexpr int idler_homing_direction = -1;

static constexpr int selector_steps_after_homing = 0;
static constexpr int idler_steps_after_homing = 533;

static constexpr int idler_steps = -500;
static constexpr int selector_steps = -828;
static constexpr int idler_parking_steps = 533;
static constexpr int pulley_parking_steps = 1500;
static constexpr bool idler_single_parking_position = true;

#endif //CONFIGURATION_H
21 changes: 21 additions & 0 deletions MM-control-01/configuration_MMUv2.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! @file
//! @author Marek Bel

#ifndef CONFIGURATION_H
#define CONFIGURATION_H

// MMUv2 configuration
// edit input file configuration_MMUv2.h.in

static constexpr int idler_homing_direction = 1;

static constexpr int selector_steps_after_homing = -3700;
static constexpr int idler_steps_after_homing = -130;

static constexpr int selector_steps = 2790/4;
static constexpr int idler_steps = 1420 / 4; // 2 msteps = 180 / 4
static constexpr int idler_parking_steps = (idler_steps / 2) + 40; // 40
static constexpr int pulley_parking_steps = 600;
static constexpr bool idler_single_parking_position = false;

#endif //CONFIGURATION_H
7 changes: 4 additions & 3 deletions MM-control-01/mmctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "motion.h"
#include "permanent_storage.h"
#include "config.h"
#include "configuration.h"

//! Keeps track of selected filament. It is used for LED signalization and it is backed up to permanent storage
//! so MMU can unload filament after power loss.
Expand Down Expand Up @@ -90,7 +91,7 @@ bool feed_filament(bool timeout)
{
// unload to PTFE tube
set_pulley_dir_pull();
for (int i = 600 + finda_limit; i > 0; i--)
for (int i = pulley_parking_steps + finda_limit; i > 0; i--)
{
do_pulley_step();
delayMicroseconds(3000);
Expand Down Expand Up @@ -337,7 +338,7 @@ static bool checkOk()
// looks ok !
// unload to PTFE tube
set_pulley_dir_pull();
for (int i = 600; i > 0; i--) // 570
for (int i = pulley_parking_steps; i > 0; i--)
{
do_pulley_step();
delayMicroseconds(3000);
Expand Down Expand Up @@ -638,7 +639,7 @@ void unload_filament_withSensor()
// correct unloading
// unload to PTFE tube
set_pulley_dir_pull();
for (int i = 450; i > 0; i--) // 570
for (int i = pulley_parking_steps - 150; i > 0; i--) // 570
{
do_pulley_step();
delayMicroseconds(5000);
Expand Down
51 changes: 40 additions & 11 deletions MM-control-01/motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
#include "config.h"
#include "tmc2130.h"
#include "shr16.h"
#include "configuration.h"

static uint8_t s_idler = 0;
static uint8_t s_selector = 0;
static bool s_selector_homed = false;
static bool s_idler_homed = false;
static bool s_idler_engaged = true;
static bool s_has_door_sensor = false;

Expand All @@ -26,7 +28,7 @@ void rehome()
shr16_set_ena(7);
tmc2130_init(tmc2130_mode);
home();
if (s_idler_engaged) park_idler(true);
park_idler(!s_idler_engaged);
}

static void rehome_idler()
Expand All @@ -38,7 +40,7 @@ static void rehome_idler()
home_idler();
int idler_steps = get_idler_steps(0, s_idler);
move_proportional(idler_steps, 0);
if (s_idler_engaged) park_idler(true);
park_idler(!s_idler_engaged);
}

void motion_set_idler_selector(uint8_t idler_selector)
Expand All @@ -55,20 +57,29 @@ void motion_set_idler_selector(uint8_t idler_selector)
//! @param selector selector
void motion_set_idler_selector(uint8_t idler, uint8_t selector)
{
if (!s_idler_homed)
{
motion_set_idler(0);
}
if (!s_selector_homed)
{
home();
s_selector = 0;
s_idler = 0;
s_selector_homed = true;
home_selector();
s_selector = 0;
s_selector_homed = true;
}
const uint8_t tries = 2;
for (uint8_t i = 0; i <= tries; ++i)
{
int idler_steps = get_idler_steps(s_idler, idler);
int selector_steps = get_selector_steps(s_selector, selector);

move_proportional(idler_steps, selector_steps);
if (idler_single_parking_position && !s_idler_engaged)
{
move_proportional(0, selector_steps);
}
else
{
move_proportional(idler_steps, selector_steps);
}
s_idler = idler;
s_selector = selector;

Expand Down Expand Up @@ -100,14 +111,28 @@ static void check_idler_drive_error()
void motion_engage_idler()
{
s_idler_engaged = true;
park_idler(true);
if (idler_single_parking_position)
{
motion_set_idler(s_idler);
}
park_idler(false);
check_idler_drive_error();
}

void motion_disengage_idler()
{
s_idler_engaged = false;
park_idler(false);
if (idler_single_parking_position)
{
if (!s_idler_homed)
{
home_idler();
s_idler_homed = true;
}
int idler_steps = get_idler_steps(s_idler, 0);
move_proportional(idler_steps, 0);
}
park_idler(true);
check_idler_drive_error();
}

Expand Down Expand Up @@ -222,7 +247,11 @@ void motion_door_sensor_detected()

void motion_set_idler(uint8_t idler)
{
home_idler();
if (!s_idler_homed)
{
home_idler();
s_idler_homed = true;
}
int idler_steps = get_idler_steps(0, idler);
move_proportional(idler_steps, 0);
s_idler = idler;
Expand Down
34 changes: 14 additions & 20 deletions MM-control-01/stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@
#include "permanent_storage.h"
#include "pins.h"
#include "tmc2130.h"
#include "configuration.h"

int8_t filament_type[EXTRUDERS] = {-1, -1, -1, -1, -1};
static bool isIdlerParked = false;

static const int selector_steps_after_homing = -3700;
static const int idler_steps_after_homing = -130;

static const int selector_steps = 2790/4;
static const int idler_steps = 1420 / 4; // 2 msteps = 180 / 4
static const int idler_parking_steps = (idler_steps / 2) + 40; // 40


static int set_idler_direction(int _steps);
static int set_selector_direction(int _steps);
Expand Down Expand Up @@ -77,14 +71,14 @@ bool home_idler()

tmc2130_init(HOMING_MODE);

move(-10, 0, 0); // move a bit in opposite direction
move(-10*idler_homing_direction, 0, 0); // move a bit in opposite direction

for (int c = 1; c > 0; c--) // not really functional, let's do it rather more times to be sure
{
delay(50);
for (int i = 0; i < 2000; i++)
{
move(1, 0,0);
move(idler_homing_direction, 0,0);
delayMicroseconds(100);
tmc2130_read_sg(0);

Expand All @@ -95,15 +89,15 @@ bool home_idler()
}
}

move(idler_steps_after_homing, 0, 0); // move to initial position
move(idler_steps_after_homing, 0, 0); // move to initial position

tmc2130_init(tmc2130_mode);
tmc2130_init(tmc2130_mode);

delay(500);
delay(500);

isIdlerParked = false;
isIdlerParked = false;

park_idler(false);
park_idler(true);

return true;
}
Expand Down Expand Up @@ -294,17 +288,17 @@ void set_pulley_dir_pull()

//! @brief Park idler
//! each filament selected has its park position, there is no park position for all filaments.
//! @param _unpark
//! * false park
//! * true engage
void park_idler(bool _unpark)
//! @param park
//! * true park
//! * false engage
void park_idler(bool park)
{
if (_unpark && isIdlerParked) // get idler in contact with filament
if (!park && isIdlerParked) // get idler in contact with filament
{
move_proportional(idler_parking_steps, 0);
isIdlerParked = false;
}
else if (!_unpark && !isIdlerParked) // park idler so filament can move freely
else if (park && !isIdlerParked) // park idler so filament can move freely
{
move_proportional(idler_parking_steps*-1, 0);
isIdlerParked = true;
Expand Down
1 change: 1 addition & 0 deletions MM-control-01/stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extern int8_t filament_type[EXTRUDERS];

void home();
bool home_idler();
bool home_selector();

int get_idler_steps(int current_filament, int next_filament);
int get_selector_steps(int current_filament, int next_filament);
Expand Down
Loading