diff --git a/.travis.yml b/.travis.yml index e8f314f9..8898b7bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 337292da..870a4391 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 .. -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) @@ -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 @@ -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 ) @@ -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() diff --git a/MM-control-01/configuration_FANTAv1.h.in b/MM-control-01/configuration_FANTAv1.h.in new file mode 100644 index 00000000..4a553d81 --- /dev/null +++ b/MM-control-01/configuration_FANTAv1.h.in @@ -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 \ No newline at end of file diff --git a/MM-control-01/configuration_MMUv2.h.in b/MM-control-01/configuration_MMUv2.h.in new file mode 100644 index 00000000..28876e02 --- /dev/null +++ b/MM-control-01/configuration_MMUv2.h.in @@ -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 \ No newline at end of file diff --git a/MM-control-01/mmctl.cpp b/MM-control-01/mmctl.cpp index e3b37288..d777874f 100644 --- a/MM-control-01/mmctl.cpp +++ b/MM-control-01/mmctl.cpp @@ -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. @@ -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); @@ -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); @@ -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); diff --git a/MM-control-01/motion.cpp b/MM-control-01/motion.cpp index 94f4048a..f9e9e1fe 100644 --- a/MM-control-01/motion.cpp +++ b/MM-control-01/motion.cpp @@ -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; @@ -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() @@ -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) @@ -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; @@ -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(); } @@ -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; diff --git a/MM-control-01/stepper.cpp b/MM-control-01/stepper.cpp index 5522cdbe..97daf89f 100644 --- a/MM-control-01/stepper.cpp +++ b/MM-control-01/stepper.cpp @@ -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); @@ -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); @@ -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; } @@ -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; diff --git a/MM-control-01/stepper.h b/MM-control-01/stepper.h index 99293364..2952889f 100644 --- a/MM-control-01/stepper.h +++ b/MM-control-01/stepper.h @@ -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); diff --git a/build.sh b/build.sh index fbaf630d..b97691f9 100755 --- a/build.sh +++ b/build.sh @@ -34,4 +34,20 @@ if [ ! -f "$BUILD_ENV.version" ]; then touch $BUILD_ENV.version || exit 9 fi -cmake --build . || exit 10 \ No newline at end of file +cmake --build . || exit 10 +cd .. + +if [ ! -d "MM-control-01_FANTAv1-build" ]; then + mkdir MM-control-01_FANTAv1-build || exit 11 +fi + +cd MM-control-01_FANTAv1-build || exit 12 + +if [ ! -f "$BUILD_ENV.version" ]; then + rm -r * + cmake -G "$BUILD_GENERATOR" -DMODEL=FANTAv1 $SCRIPT_PATH || exit 13 + touch $BUILD_ENV.version || exit 14 +fi + +cmake --build . || exit 15 +cd .. \ No newline at end of file