├── .gitattributes ├── .gitignore ├── Bootloader ├── README.TXT └── hardware │ └── arduino │ └── bootloaders │ └── optiboot │ ├── Makefile │ ├── README.TXT │ ├── boot.h │ ├── makeall │ ├── omake │ ├── omake.bat │ ├── optiboot.c │ ├── pin_defs.h │ └── stk500.h ├── Firmware └── Motion_Engine │ ├── DFMoco.ino │ ├── Debug.cpp │ ├── Debug.h │ ├── LICENSE.txt │ ├── MotionEngineProtocol.pdf │ ├── Motion_Engine.hex │ ├── Motion_Engine.ino │ ├── NMX Commands 0.12.1.pdf │ ├── NMX Commands 0.13 w-data types.pdf │ ├── NMX Commands.ods │ ├── NMX Commands.pdf │ ├── OMMoCoPrint.cpp │ ├── OMMoCoPrint.h │ ├── OM_CameraMaster.ino │ ├── OM_Camera_Control.ino │ ├── OM_ControlCycle.ino │ ├── OM_Debug.ino │ ├── OM_DevAddr.ino │ ├── OM_EEPROM.ino │ ├── OM_KeyFrameControl.ino │ ├── OM_LimitHandler.ino │ ├── OM_MotorMaster.h │ ├── OM_MotorMaster.ino │ ├── OM_Motor_Control.ino │ ├── OM_Motor_Travel.ino │ ├── OM_Serial_Com_Client.ino │ ├── README.txt │ └── Sample Commands.txt ├── README.md └── Web Updater ├── fullIndex.xml └── index.xml /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | #Command lists 5 | *.pdf 6 | 7 | #Visual Studio Solution and Project Files 8 | *.sln 9 | *.vcxproj 10 | *.vcxproj.filters 11 | 12 | #Visual Micro files 13 | *.vsarduino.h 14 | *.vmps.xml 15 | 16 | # User-specific files 17 | *.suo 18 | *.user 19 | *.sln.docstates 20 | 21 | # Build results 22 | 23 | [Dd]ebug/ 24 | [Rr]elease/ 25 | x64/ 26 | build/ 27 | [Bb]in/ 28 | [Oo]bj/ 29 | 30 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets 31 | !packages/*/build/ 32 | 33 | # MSTest test Results 34 | [Tt]est[Rr]esult*/ 35 | [Bb]uild[Ll]og.* 36 | 37 | *_i.c 38 | *_p.c 39 | *.ilk 40 | *.meta 41 | *.obj 42 | *.pch 43 | *.pdb 44 | *.pgc 45 | *.pgd 46 | *.rsp 47 | *.sbr 48 | *.tlb 49 | *.tli 50 | *.tlh 51 | *.tmp 52 | *.tmp_proj 53 | *.log 54 | *.vspscc 55 | *.vssscc 56 | .builds 57 | *.pidb 58 | *.log 59 | *.scc 60 | 61 | # Visual C++ cache files 62 | ipch/ 63 | *.aps 64 | *.ncb 65 | *.opensdf 66 | *.sdf 67 | *.cachefile 68 | 69 | # Visual Studio profiler 70 | *.psess 71 | *.vsp 72 | *.vspx 73 | 74 | # Guidance Automation Toolkit 75 | *.gpState 76 | 77 | # ReSharper is a .NET coding add-in 78 | _ReSharper*/ 79 | *.[Rr]e[Ss]harper 80 | 81 | # TeamCity is a build add-in 82 | _TeamCity* 83 | 84 | # DotCover is a Code Coverage Tool 85 | *.dotCover 86 | 87 | # NCrunch 88 | *.ncrunch* 89 | .*crunch*.local.xml 90 | 91 | # Installshield output folder 92 | [Ee]xpress/ 93 | 94 | # DocProject is a documentation generator add-in 95 | DocProject/buildhelp/ 96 | DocProject/Help/*.HxT 97 | DocProject/Help/*.HxC 98 | DocProject/Help/*.hhc 99 | DocProject/Help/*.hhk 100 | DocProject/Help/*.hhp 101 | DocProject/Help/Html2 102 | DocProject/Help/html 103 | 104 | # Click-Once directory 105 | publish/ 106 | 107 | # Publish Web Output 108 | *.Publish.xml 109 | 110 | # NuGet Packages Directory 111 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 112 | #packages/ 113 | 114 | # Windows Azure Build Output 115 | csx 116 | *.build.csdef 117 | 118 | # Windows Store app package directory 119 | AppPackages/ 120 | 121 | # Others 122 | sql/ 123 | *.Cache 124 | ClientBin/ 125 | [Ss]tyle[Cc]op.* 126 | ~$* 127 | *~ 128 | *.dbmdl 129 | *.[Pp]ublish.xml 130 | *.pfx 131 | *.publishsettings 132 | 133 | # RIA/Silverlight projects 134 | Generated_Code/ 135 | 136 | # Backup & report files from converting an old project file to a newer 137 | # Visual Studio version. Backup files are not needed, because we have git ;-) 138 | _UpgradeReport_Files/ 139 | Backup*/ 140 | UpgradeLog*.XML 141 | UpgradeLog*.htm 142 | 143 | # SQL Server files 144 | App_Data/*.mdf 145 | App_Data/*.ldf 146 | 147 | 148 | #LightSwitch generated files 149 | GeneratedArtifacts/ 150 | _Pvt_Extensions/ 151 | ModelManifest.xml 152 | 153 | # ========================= 154 | # Windows detritus 155 | # ========================= 156 | 157 | # Windows image file caches 158 | Thumbs.db 159 | ehthumbs.db 160 | 161 | # Folder config file 162 | Desktop.ini 163 | 164 | # Recycle Bin used on file shares 165 | $RECYCLE.BIN/ 166 | 167 | # Mac desktop service store files 168 | .DS_Store 169 | 170 | # Open Office lock files 171 | *.ods# 172 | ~lock.* 173 | 174 | *.ods# 175 | -------------------------------------------------------------------------------- /Bootloader/README.TXT: -------------------------------------------------------------------------------- 1 | nanoMoCo uses a slightly modified form of optiboot to allow it to be programmed over the RS485 2 | bus using the standard IDE. 3 | 4 | To install bootloader: 5 | 6 | - Need ISP programmer 7 | 8 | ( using Arduino built-in commands ) 9 | 10 | 1) Copy contents of bootloader (hardware/) into Arduino directory/bundle 11 | 2) cd all of the way down into optiboot directory 12 | 3) Modify makefile to point to correct port for your ISP programmer 13 | 4) omake nanoMoCo_isp 14 | 15 | ( using avrdude, make, etc. ) 16 | 17 | 1) cd all the way down into optiboot directory 18 | 2) make nanoMoCo_isp 19 | 20 | 21 | -------------------------------------------------------------------------------- /Bootloader/hardware/arduino/bootloaders/optiboot/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for ATmegaBOOT 2 | # E.Lins, 18.7.2005 3 | # $Id$ 4 | # 5 | # Instructions 6 | # 7 | # To make bootloader .hex file: 8 | # make diecimila 9 | # make lilypad 10 | # make ng 11 | # etc... 12 | # 13 | # To burn bootloader .hex file: 14 | # make diecimila_isp 15 | # make lilypad_isp 16 | # make ng_isp 17 | # etc... 18 | 19 | # program name should not be changed... 20 | PROGRAM = optiboot 21 | 22 | # The default behavior is to build using tools that are in the users 23 | # current path variables, but we can also build using an installed 24 | # Arduino user IDE setup, or the Arduino source tree. 25 | # Uncomment this next lines to build within the arduino environment, 26 | # using the arduino-included avrgcc toolset (mac and pc) 27 | ENV ?= arduino 28 | # ENV ?= arduinodev 29 | OS ?= macosx 30 | # OS ?= windows 31 | 32 | 33 | # enter the parameters for the avrdude isp tool 34 | ISPTOOL = stk500v2 35 | ISPPORT = /dev/tty.usbmodemfa131 36 | ISPSPEED = -b 115200 37 | 38 | MCU_TARGET = atmega168 39 | LDSECTIONS = -Wl,--section-start=.text=0x3e00 -Wl,--section-start=.version=0x3ffe 40 | 41 | # Build environments 42 | # Start of some ugly makefile-isms to allow optiboot to be built 43 | # in several different environments. See the README.TXT file for 44 | # details. 45 | 46 | # default 47 | fixpath = $(1) 48 | 49 | ifeq ($(ENV), arduino) 50 | # For Arduino, we assume that we're connected to the optiboot directory 51 | # included with the arduino distribution, which means that the full set 52 | # of avr-tools are "right up there" in standard places. 53 | TOOLROOT = ../../../tools 54 | GCCROOT = $(TOOLROOT)/avr/bin/ 55 | AVRDUDE_CONF = -C$(TOOLROOT)/avr/etc/avrdude.conf 56 | 57 | ifeq ($(OS), windows) 58 | # On windows, SOME of the tool paths will need to have backslashes instead 59 | # of forward slashes (because they use windows cmd.exe for execution instead 60 | # of a unix/mingw shell?) We also have to ensure that a consistent shell 61 | # is used even if a unix shell is installed (ie as part of WINAVR) 62 | fixpath = $(subst /,\,$1) 63 | SHELL = cmd.exe 64 | endif 65 | 66 | else ifeq ($(ENV), arduinodev) 67 | # Arduino IDE source code environment. Use the unpacked compilers created 68 | # by the build (you'll need to do "ant build" first.) 69 | ifeq ($(OS), macosx) 70 | TOOLROOT = ../../../../build/macosx/work/Arduino.app/Contents/Resources/Java/hardware/tools 71 | endif 72 | ifeq ($(OS), windows) 73 | TOOLROOT = ../../../../build/windows/work/hardware/tools 74 | endif 75 | 76 | GCCROOT = $(TOOLROOT)/avr/bin/ 77 | AVRDUDE_CONF = -C$(TOOLROOT)/avr/etc/avrdude.conf 78 | 79 | else 80 | GCCROOT = 81 | AVRDUDE_CONF = 82 | endif 83 | # 84 | # End of build environment code. 85 | 86 | 87 | # the efuse should really be 0xf8; since, however, only the lower 88 | # three bits of that byte are used on the atmega168, avrdude gets 89 | # confused if you specify 1's for the higher bits, see: 90 | # http://tinker.it/now/2007/02/24/the-tale-of-avrdude-atmega168-and-extended-bits-fuses/ 91 | # 92 | # similarly, the lock bits should be 0xff instead of 0x3f (to 93 | # unlock the bootloader section) and 0xcf instead of 0x2f (to 94 | # lock it), but since the high two bits of the lock byte are 95 | # unused, avrdude would get confused. 96 | 97 | ISPFUSES = $(GCCROOT)avrdude $(AVRDUDE_CONF) -c $(ISPTOOL) \ 98 | -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \ 99 | -e -u -U lock:w:0x3f:m -U efuse:w:0x$(EFUSE):m \ 100 | -U hfuse:w:0x$(HFUSE):m -U lfuse:w:0x$(LFUSE):m 101 | ISPFLASH = $(GCCROOT)avrdude $(AVRDUDE_CONF) -c $(ISPTOOL) \ 102 | -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \ 103 | -U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x2f:m 104 | 105 | STK500 = "C:\Program Files\Atmel\AVR Tools\STK500\Stk500.exe" 106 | STK500-1 = $(STK500) -e -d$(MCU_TARGET) -pf -vf -if$(PROGRAM)_$(TARGET).hex \ 107 | -lFF -LFF -f$(HFUSE)$(LFUSE) -EF8 -ms -q -cUSB -I200kHz -s -wt 108 | STK500-2 = $(STK500) -d$(MCU_TARGET) -ms -q -lCF -LCF -cUSB -I200kHz -s -wt 109 | 110 | OBJ = $(PROGRAM).o 111 | OPTIMIZE = -Os -fno-inline-small-functions -fno-split-wide-types -mshort-calls 112 | 113 | DEFS = 114 | LIBS = 115 | 116 | CC = $(GCCROOT)avr-gcc 117 | 118 | # Override is only needed by avr-lib build system. 119 | 120 | override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(AVR_FREQ) $(DEFS) 121 | override LDFLAGS = $(LDSECTIONS) -Wl,--relax -Wl,--gc-sections -nostartfiles -nostdlib 122 | 123 | OBJCOPY = $(GCCROOT)avr-objcopy 124 | OBJDUMP = $(call fixpath,$(GCCROOT)avr-objdump) 125 | 126 | SIZE = $(GCCROOT)avr-size 127 | 128 | # Test platforms 129 | # Virtual boot block test 130 | virboot328: TARGET = atmega328 131 | virboot328: MCU_TARGET = atmega328p 132 | virboot328: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' '-DVIRTUAL_BOOT' 133 | virboot328: AVR_FREQ = 16000000L 134 | virboot328: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe 135 | virboot328: $(PROGRAM)_atmega328.hex 136 | virboot328: $(PROGRAM)_atmega328.lst 137 | 138 | # 20MHz clocked platforms 139 | # 140 | # These are capable of 230400 baud, or 115200 baud on PC (Arduino Avrdude issue) 141 | # 142 | 143 | pro20: TARGET = pro_20mhz 144 | pro20: MCU_TARGET = atmega168 145 | pro20: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' 146 | pro20: AVR_FREQ = 20000000L 147 | pro20: $(PROGRAM)_pro_20mhz.hex 148 | pro20: $(PROGRAM)_pro_20mhz.lst 149 | 150 | pro20_isp: pro20 151 | pro20_isp: TARGET = pro_20mhz 152 | # 2.7V brownout 153 | pro20_isp: HFUSE = DD 154 | # Full swing xtal (20MHz) 258CK/14CK+4.1ms 155 | pro20_isp: LFUSE = C6 156 | # 512 byte boot 157 | pro20_isp: EFUSE = 04 158 | pro20_isp: isp 159 | 160 | # 16MHz clocked platforms 161 | # 162 | # These are capable of 230400 baud, or 115200 baud on PC (Arduino Avrdude issue) 163 | # 164 | 165 | pro16: TARGET = pro_16MHz 166 | pro16: MCU_TARGET = atmega168 167 | pro16: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' 168 | pro16: AVR_FREQ = 16000000L 169 | pro16: $(PROGRAM)_pro_16MHz.hex 170 | pro16: $(PROGRAM)_pro_16MHz.lst 171 | 172 | pro16_isp: pro16 173 | pro16_isp: TARGET = pro_16MHz 174 | # 2.7V brownout 175 | pro16_isp: HFUSE = DD 176 | # Full swing xtal (20MHz) 258CK/14CK+4.1ms 177 | pro16_isp: LFUSE = C6 178 | # 512 byte boot 179 | pro16_isp: EFUSE = 04 180 | pro16_isp: isp 181 | 182 | # Diecimila, Duemilanove with m168, and NG use identical bootloaders 183 | # Call it "atmega168" for generality and clarity, keep "diecimila" for 184 | # backward compatibility of makefile 185 | # 186 | atmega168: TARGET = atmega168 187 | atmega168: MCU_TARGET = atmega168 188 | atmega168: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' 189 | atmega168: AVR_FREQ = 16000000L 190 | atmega168: $(PROGRAM)_atmega168.hex 191 | atmega168: $(PROGRAM)_atmega168.lst 192 | 193 | atmega168_isp: atmega168 194 | atmega168_isp: TARGET = atmega168 195 | # 2.7V brownout 196 | atmega168_isp: HFUSE = DD 197 | # Low power xtal (16MHz) 16KCK/14CK+65ms 198 | atmega168_isp: LFUSE = FF 199 | # 512 byte boot 200 | atmega168_isp: EFUSE = 04 201 | atmega168_isp: isp 202 | 203 | diecimila: TARGET = diecimila 204 | diecimila: MCU_TARGET = atmega168 205 | diecimila: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' 206 | diecimila: AVR_FREQ = 16000000L 207 | diecimila: $(PROGRAM)_diecimila.hex 208 | diecimila: $(PROGRAM)_diecimila.lst 209 | 210 | diecimila_isp: diecimila 211 | diecimila_isp: TARGET = diecimila 212 | # 2.7V brownout 213 | diecimila_isp: HFUSE = DD 214 | # Low power xtal (16MHz) 16KCK/14CK+65ms 215 | diecimila_isp: LFUSE = FF 216 | # 512 byte boot 217 | diecimila_isp: EFUSE = 04 218 | diecimila_isp: isp 219 | 220 | atmega328: TARGET = atmega328 221 | atmega328: MCU_TARGET = atmega328p 222 | atmega328: CFLAGS += '-DLED_DATA_FLASH' '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' 223 | atmega328: AVR_FREQ = 16000000L 224 | atmega328: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe 225 | atmega328: $(PROGRAM)_atmega328.hex 226 | atmega328: $(PROGRAM)_atmega328.lst 227 | 228 | atmega328_isp: atmega328 229 | atmega328_isp: TARGET = atmega328 230 | atmega328_isp: MCU_TARGET = atmega328p 231 | # 512 byte boot, SPIEN 232 | atmega328_isp: HFUSE = DE 233 | # Low power xtal (16MHz) 16KCK/14CK+65ms 234 | atmega328_isp: LFUSE = FF 235 | # 2.7V brownout 236 | atmega328_isp: EFUSE = 05 237 | atmega328_isp: isp 238 | 239 | # cchurch - added for nanoMoCo - notice slower baud rate 240 | nanoMoCo: TARGET = nanoMoCo 241 | nanoMoCo: MCU_TARGET = atmega328p 242 | nanoMoCo: CFLAGS += '-DFORCE_HARD_UART' '-DBAUD_RATE=115200' 243 | nanoMoCo: AVR_FREQ = 16000000L 244 | nanoMoCo: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe 245 | nanoMoCo: $(PROGRAM)_nanoMoCo.hex 246 | nanoMoCo: $(PROGRAM)_nanoMoCo.lst 247 | 248 | nanoMoCo_isp: nanoMoCo 249 | nanoMoCo_isp: TARGET = nanoMoCo 250 | nanoMoCo_isp: MCU_TARGET = atmega328p 251 | # 512 byte boot, SPIEN 252 | nanoMoCo_isp: HFUSE = DE 253 | # Low power xtal (16MHz) 16KCK/14CK+65ms 254 | nanoMoCo_isp: LFUSE = FF 255 | # 2.7V brownout 256 | nanoMoCo_isp: EFUSE = 05 257 | nanoMoCo_isp: isp 258 | 259 | # Sanguino has a minimum boot size of 1024 bytes, so enable extra functions 260 | # 261 | sanguino: TARGET = atmega644p 262 | sanguino: MCU_TARGET = atmega644p 263 | sanguino: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' '-DBIGBOOT' 264 | sanguino: AVR_FREQ = 16000000L 265 | sanguino: LDSECTIONS = -Wl,--section-start=.text=0xfc00 266 | sanguino: $(PROGRAM)_atmega644p.hex 267 | sanguino: $(PROGRAM)_atmega644p.lst 268 | 269 | sanguino_isp: sanguino 270 | sanguino_isp: TARGET = atmega644p 271 | sanguino_isp: MCU_TARGET = atmega644p 272 | # 1024 byte boot 273 | sanguino_isp: HFUSE = DE 274 | # Low power xtal (16MHz) 16KCK/14CK+65ms 275 | sanguino_isp: LFUSE = FF 276 | # 2.7V brownout 277 | sanguino_isp: EFUSE = 05 278 | sanguino_isp: isp 279 | 280 | # Mega has a minimum boot size of 1024 bytes, so enable extra functions 281 | #mega: TARGET = atmega1280 282 | mega: MCU_TARGET = atmega1280 283 | mega: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' '-DBIGBOOT' 284 | mega: AVR_FREQ = 16000000L 285 | mega: LDSECTIONS = -Wl,--section-start=.text=0x1fc00 286 | mega: $(PROGRAM)_atmega1280.hex 287 | mega: $(PROGRAM)_atmega1280.lst 288 | 289 | mega_isp: mega 290 | mega_isp: TARGET = atmega1280 291 | mega_isp: MCU_TARGET = atmega1280 292 | # 1024 byte boot 293 | mega_isp: HFUSE = DE 294 | # Low power xtal (16MHz) 16KCK/14CK+65ms 295 | mega_isp: LFUSE = FF 296 | # 2.7V brownout 297 | mega_isp: EFUSE = 05 298 | mega_isp: isp 299 | 300 | # ATmega8 301 | # 302 | atmega8: TARGET = atmega8 303 | atmega8: MCU_TARGET = atmega8 304 | atmega8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' 305 | atmega8: AVR_FREQ = 16000000L 306 | atmega8: LDSECTIONS = -Wl,--section-start=.text=0x1e00 -Wl,--section-start=.version=0x1ffe 307 | atmega8: $(PROGRAM)_atmega8.hex 308 | atmega8: $(PROGRAM)_atmega8.lst 309 | 310 | atmega8_isp: atmega8 311 | atmega8_isp: TARGET = atmega8 312 | atmega8_isp: MCU_TARGET = atmega8 313 | # SPIEN, CKOPT, Bootsize=512B 314 | atmega8_isp: HFUSE = CC 315 | # 2.7V brownout, Low power xtal (16MHz) 16KCK/14CK+65ms 316 | atmega8_isp: LFUSE = BF 317 | atmega8_isp: isp 318 | 319 | # ATmega88 320 | # 321 | atmega88: TARGET = atmega88 322 | atmega88: MCU_TARGET = atmega88 323 | atmega88: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' 324 | atmega88: AVR_FREQ = 16000000L 325 | atmega88: LDSECTIONS = -Wl,--section-start=.text=0x1e00 -Wl,--section-start=.version=0x1ffe 326 | atmega88: $(PROGRAM)_atmega88.hex 327 | atmega88: $(PROGRAM)_atmega88.lst 328 | 329 | atmega88_isp: atmega88 330 | atmega88_isp: TARGET = atmega88 331 | atmega88_isp: MCU_TARGET = atmega88 332 | # 2.7V brownout 333 | atmega88_isp: HFUSE = DD 334 | # Low power xtal (16MHz) 16KCK/14CK+65ms 335 | atemga88_isp: LFUSE = FF 336 | # 512 byte boot 337 | atmega88_isp: EFUSE = 04 338 | atmega88_isp: isp 339 | 340 | 341 | # 8MHz clocked platforms 342 | # 343 | # These are capable of 115200 baud 344 | # 345 | 346 | lilypad: TARGET = lilypad 347 | lilypad: MCU_TARGET = atmega168 348 | lilypad: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' 349 | lilypad: AVR_FREQ = 8000000L 350 | lilypad: $(PROGRAM)_lilypad.hex 351 | lilypad: $(PROGRAM)_lilypad.lst 352 | 353 | lilypad_isp: lilypad 354 | lilypad_isp: TARGET = lilypad 355 | # 2.7V brownout 356 | lilypad_isp: HFUSE = DD 357 | # Internal 8MHz osc (8MHz) Slow rising power 358 | lilypad_isp: LFUSE = E2 359 | # 512 byte boot 360 | lilypad_isp: EFUSE = 04 361 | lilypad_isp: isp 362 | 363 | lilypad_resonator: TARGET = lilypad_resonator 364 | lilypad_resonator: MCU_TARGET = atmega168 365 | lilypad_resonator: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' 366 | lilypad_resonator: AVR_FREQ = 8000000L 367 | lilypad_resonator: $(PROGRAM)_lilypad_resonator.hex 368 | lilypad_resonator: $(PROGRAM)_lilypad_resonator.lst 369 | 370 | lilypad_resonator_isp: lilypad_resonator 371 | lilypad_resonator_isp: TARGET = lilypad_resonator 372 | # 2.7V brownout 373 | lilypad_resonator_isp: HFUSE = DD 374 | # Full swing xtal (20MHz) 258CK/14CK+4.1ms 375 | lilypad_resonator_isp: LFUSE = C6 376 | # 512 byte boot 377 | lilypad_resonator_isp: EFUSE = 04 378 | lilypad_resonator_isp: isp 379 | 380 | pro8: TARGET = pro_8MHz 381 | pro8: MCU_TARGET = atmega168 382 | pro8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' 383 | pro8: AVR_FREQ = 8000000L 384 | pro8: $(PROGRAM)_pro_8MHz.hex 385 | pro8: $(PROGRAM)_pro_8MHz.lst 386 | 387 | pro8_isp: pro8 388 | pro8_isp: TARGET = pro_8MHz 389 | # 2.7V brownout 390 | pro8_isp: HFUSE = DD 391 | # Full swing xtal (20MHz) 258CK/14CK+4.1ms 392 | pro8_isp: LFUSE = C6 393 | # 512 byte boot 394 | pro8_isp: EFUSE = 04 395 | pro8_isp: isp 396 | 397 | atmega328_pro8: TARGET = atmega328_pro_8MHz 398 | atmega328_pro8: MCU_TARGET = atmega328p 399 | atmega328_pro8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' 400 | atmega328_pro8: AVR_FREQ = 8000000L 401 | atmega328_pro8: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe 402 | atmega328_pro8: $(PROGRAM)_atmega328_pro_8MHz.hex 403 | atmega328_pro8: $(PROGRAM)_atmega328_pro_8MHz.lst 404 | 405 | atmega328_pro8_isp: atmega328_pro8 406 | atmega328_pro8_isp: TARGET = atmega328_pro_8MHz 407 | atmega328_pro8_isp: MCU_TARGET = atmega328p 408 | # 512 byte boot, SPIEN 409 | atmega328_pro8_isp: HFUSE = DE 410 | # Low power xtal (16MHz) 16KCK/14CK+65ms 411 | atmega328_pro8_isp: LFUSE = FF 412 | # 2.7V brownout 413 | atmega328_pro8_isp: EFUSE = 05 414 | atmega328_pro8_isp: isp 415 | 416 | # 1MHz clocked platforms 417 | # 418 | # These are capable of 9600 baud 419 | # 420 | 421 | luminet: TARGET = luminet 422 | luminet: MCU_TARGET = attiny84 423 | luminet: CFLAGS += '-DLED_START_FLASHES=3' '-DSOFT_UART' '-DBAUD_RATE=9600' 424 | luminet: CFLAGS += '-DVIRTUAL_BOOT_PARTITION' 425 | luminet: AVR_FREQ = 1000000L 426 | luminet: LDSECTIONS = -Wl,--section-start=.text=0x1d00 -Wl,--section-start=.version=0x1efe 427 | luminet: $(PROGRAM)_luminet.hex 428 | luminet: $(PROGRAM)_luminet.lst 429 | 430 | luminet_isp: luminet 431 | luminet_isp: TARGET = luminet 432 | luminet_isp: MCU_TARGET = attiny84 433 | # Brownout disabled 434 | luminet_isp: HFUSE = DF 435 | # 1MHz internal oscillator, slowly rising power 436 | luminet_isp: LFUSE = 62 437 | # Self-programming enable 438 | luminet_isp: EFUSE = FE 439 | luminet_isp: isp 440 | 441 | # 442 | # Generic build instructions 443 | # 444 | # 445 | 446 | isp: $(TARGET) 447 | $(ISPFUSES) 448 | $(ISPFLASH) 449 | 450 | isp-stk500: $(PROGRAM)_$(TARGET).hex 451 | $(STK500-1) 452 | $(STK500-2) 453 | 454 | %.elf: $(OBJ) 455 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) 456 | $(SIZE) $@ 457 | 458 | clean: 459 | rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex 460 | 461 | %.lst: %.elf 462 | $(OBJDUMP) -h -S $< > $@ 463 | 464 | %.hex: %.elf 465 | $(OBJCOPY) -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex $< $@ 466 | 467 | %.srec: %.elf 468 | $(OBJCOPY) -j .text -j .data -j .version --set-section-flags .version=alloc,load -O srec $< $@ 469 | 470 | %.bin: %.elf 471 | $(OBJCOPY) -j .text -j .data -j .version --set-section-flags .version=alloc,load -O binary $< $@ 472 | -------------------------------------------------------------------------------- /Bootloader/hardware/arduino/bootloaders/optiboot/README.TXT: -------------------------------------------------------------------------------- 1 | This directory contains the Optiboot small bootloader for AVR 2 | microcontrollers, somewhat modified specifically for the Arduino 3 | environment. 4 | 5 | Optiboot is more fully described here: http://code.google.com/p/optiboot/ 6 | and is the work of Peter Knight (aka Cathedrow), building on work of Jason P 7 | Kyle, Spiff, and Ladyada. Arduino-specific modification are by Bill 8 | Westfield (aka WestfW) 9 | 10 | Arduino-specific issues are tracked as part of the Arduino project 11 | at http://code.google.com/p/arduino 12 | 13 | 14 | ------------------------------------------------------------ 15 | Building optiboot for Arduino. 16 | 17 | Production builds of optiboot for Arduino are done on a Mac in "unix mode" 18 | using CrossPack-AVR-20100115. CrossPack tracks WINAVR (for windows), which 19 | is just a package of avr-gcc and related utilities, so similar builds should 20 | work on Windows or Linux systems. 21 | 22 | One of the Arduino-specific changes is modifications to the makefile to 23 | allow building optiboot using only the tools installed as part of the 24 | Arduino environment, or the Arduino source development tree. All three 25 | build procedures should yield identical binaries (.hex files) (although 26 | this may change if compiler versions drift apart between CrossPack and 27 | the Arduino IDE.) 28 | 29 | 30 | Building Optiboot in the Arduino IDE Install. 31 | 32 | Work in the .../hardware/arduino/bootloaders/optiboot/ and use the 33 | "omake " command, which just generates a command that uses 34 | the arduino-included "make" utility with a command like: 35 | make OS=windows ENV=arduino 36 | or make OS=macosx ENV=arduino 37 | On windows, this assumes you're using the windows command shell. If 38 | you're using a cygwin or mingw shell, or have one of those in your 39 | path, the build will probably break due to slash vs backslash issues. 40 | On a Mac, if you have the developer tools installed, you can use the 41 | Apple-supplied version of make. 42 | The makefile uses relative paths ("../../../tools/" and such) to find 43 | the programs it needs, so you need to work in the existing optiboot 44 | directory (or something created at the same "level") for it to work. 45 | 46 | 47 | Building Optiboot in the Arduino Source Development Install. 48 | 49 | In this case, there is no special shell script, and you're assumed to 50 | have "make" installed somewhere in your path. 51 | Build the Arduino source ("ant build") to unpack the tools into the 52 | expected directory. 53 | Work in Arduino/hardware/arduino/bootloaders/optiboot and use 54 | make OS=windows ENV=arduinodev 55 | or make OS=macosx ENV=arduinodev 56 | 57 | 58 | Programming Chips Using the _isp Targets 59 | 60 | The CPU targets have corresponding ISP targets that will actuall 61 | program the bootloader into a chip. "atmega328_isp" for the atmega328, 62 | for example. These will set the fuses and lock bits as appropriate as 63 | well as uploading the bootloader code. 64 | 65 | The makefiles default to using a USB programmer, but you can use 66 | a serial programmer like ArduinoISP by changing the appropriate 67 | variables when you invoke make: 68 | 69 | make ISPTOOL=stk500v1 ISPPORT=/dev/tty.usbserial-A20e1eAN \ 70 | ISPSPEED=-b19200 atmega328_isp 71 | 72 | The "atmega8_isp" target does not currently work, because the mega8 73 | doesn't have the "extended" fuse that the generic ISP target wants to 74 | pass on to avrdude. You'll need to run avrdude manually. 75 | 76 | 77 | Standard Targets 78 | 79 | I've reduced the pre-built and source-version-controlled targets 80 | (.hex and .lst files included in the git repository) to just the 81 | three basic 16MHz targets: atmega8, atmega16, atmega328. 82 | -------------------------------------------------------------------------------- /Bootloader/hardware/arduino/bootloaders/optiboot/makeall: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | make clean 3 | # 4 | # The "big three" standard bootloaders. 5 | make atmega8 6 | make atmega168 7 | make atmega328 8 | # 9 | # additional buildable platforms of 10 | # somewhat questionable support level 11 | make lilypad 12 | make lilypad_resonator 13 | make pro8 14 | make pro16 15 | make pro20 16 | make atmega328_pro8 17 | make sanguino 18 | make mega 19 | make atmega88 20 | make luminet 21 | -------------------------------------------------------------------------------- /Bootloader/hardware/arduino/bootloaders/optiboot/omake: -------------------------------------------------------------------------------- 1 | echo ../../../tools/avr/bin/make OS=macosx ENV=arduino $* 2 | ../../../tools/avr/bin/make OS=macosx ENV=arduino $* 3 | -------------------------------------------------------------------------------- /Bootloader/hardware/arduino/bootloaders/optiboot/omake.bat: -------------------------------------------------------------------------------- 1 | ..\..\..\tools\avr\utils\bin\make OS=windows ENV=arduino %* 2 | -------------------------------------------------------------------------------- /Bootloader/hardware/arduino/bootloaders/optiboot/optiboot.c: -------------------------------------------------------------------------------- 1 | /**********************************************************/ 2 | /* Optiboot bootloader for Arduino */ 3 | /* */ 4 | /* http://optiboot.googlecode.com */ 5 | /* */ 6 | /* Arduino-maintained version : See README.TXT */ 7 | /* http://code.google.com/p/arduino/ */ 8 | /* */ 9 | /* Heavily optimised bootloader that is faster and */ 10 | /* smaller than the Arduino standard bootloader */ 11 | /* */ 12 | /* Enhancements: */ 13 | /* Fits in 512 bytes, saving 1.5K of code space */ 14 | /* Background page erasing speeds up programming */ 15 | /* Higher baud rate speeds up programming */ 16 | /* Written almost entirely in C */ 17 | /* Customisable timeout with accurate timeconstant */ 18 | /* Optional virtual UART. No hardware UART required. */ 19 | /* Optional virtual boot partition for devices without. */ 20 | /* */ 21 | /* What you lose: */ 22 | /* Implements a skeleton STK500 protocol which is */ 23 | /* missing several features including EEPROM */ 24 | /* programming and non-page-aligned writes */ 25 | /* High baud rate breaks compatibility with standard */ 26 | /* Arduino flash settings */ 27 | /* */ 28 | /* Fully supported: */ 29 | /* ATmega168 based devices (Diecimila etc) */ 30 | /* ATmega328P based devices (Duemilanove etc) */ 31 | /* */ 32 | /* Alpha test */ 33 | /* ATmega1280 based devices (Arduino Mega) */ 34 | /* */ 35 | /* Work in progress: */ 36 | /* ATmega644P based devices (Sanguino) */ 37 | /* ATtiny84 based devices (Luminet) */ 38 | /* */ 39 | /* Does not support: */ 40 | /* USB based devices (eg. Teensy) */ 41 | /* */ 42 | /* Assumptions: */ 43 | /* The code makes several assumptions that reduce the */ 44 | /* code size. They are all true after a hardware reset, */ 45 | /* but may not be true if the bootloader is called by */ 46 | /* other means or on other hardware. */ 47 | /* No interrupts can occur */ 48 | /* UART and Timer 1 are set to their reset state */ 49 | /* SP points to RAMEND */ 50 | /* */ 51 | /* Code builds on code, libraries and optimisations from: */ 52 | /* stk500boot.c by Jason P. Kyle */ 53 | /* Arduino bootloader http://arduino.cc */ 54 | /* Spiff's 1K bootloader http://spiffie.org/know/arduino_1k_bootloader/bootloader.shtml */ 55 | /* avr-libc project http://nongnu.org/avr-libc */ 56 | /* Adaboot http://www.ladyada.net/library/arduino/bootloader.html */ 57 | /* AVR305 Atmel Application Note */ 58 | /* */ 59 | /* This program is free software; you can redistribute it */ 60 | /* and/or modify it under the terms of the GNU General */ 61 | /* Public License as published by the Free Software */ 62 | /* Foundation; either version 2 of the License, or */ 63 | /* (at your option) any later version. */ 64 | /* */ 65 | /* This program is distributed in the hope that it will */ 66 | /* be useful, but WITHOUT ANY WARRANTY; without even the */ 67 | /* implied warranty of MERCHANTABILITY or FITNESS FOR A */ 68 | /* PARTICULAR PURPOSE. See the GNU General Public */ 69 | /* License for more details. */ 70 | /* */ 71 | /* You should have received a copy of the GNU General */ 72 | /* Public License along with this program; if not, write */ 73 | /* to the Free Software Foundation, Inc., */ 74 | /* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 75 | /* */ 76 | /* Licence can be viewed at */ 77 | /* http://www.fsf.org/licenses/gpl.txt */ 78 | /* */ 79 | /**********************************************************/ 80 | 81 | 82 | /**********************************************************/ 83 | /* */ 84 | /* Optional defines: */ 85 | /* */ 86 | /**********************************************************/ 87 | /* */ 88 | /* BIG_BOOT: */ 89 | /* Build a 1k bootloader, not 512 bytes. This turns on */ 90 | /* extra functionality. */ 91 | /* */ 92 | /* BAUD_RATE: */ 93 | /* Set bootloader baud rate. */ 94 | /* */ 95 | /* LUDICROUS_SPEED: */ 96 | /* 230400 baud :-) */ 97 | /* */ 98 | /* SOFT_UART: */ 99 | /* Use AVR305 soft-UART instead of hardware UART. */ 100 | /* */ 101 | /* LED_START_FLASHES: */ 102 | /* Number of LED flashes on bootup. */ 103 | /* */ 104 | /* LED_DATA_FLASH: */ 105 | /* Flash LED when transferring data. For boards without */ 106 | /* TX or RX LEDs, or for people who like blinky lights. */ 107 | /* */ 108 | /* SUPPORT_EEPROM: */ 109 | /* Support reading and writing from EEPROM. This is not */ 110 | /* used by Arduino, so off by default. */ 111 | /* */ 112 | /* TIMEOUT_MS: */ 113 | /* Bootloader timeout period, in milliseconds. */ 114 | /* 500,1000,2000,4000,8000 supported. */ 115 | /* */ 116 | /**********************************************************/ 117 | 118 | /**********************************************************/ 119 | /* Version Numbers! */ 120 | /* */ 121 | /* Arduino Optiboot now includes this Version number in */ 122 | /* the source and object code. */ 123 | /* */ 124 | /* Version 3 was released as zip from the optiboot */ 125 | /* repository and was distributed with Arduino 0022. */ 126 | /* Version 4 starts with the arduino repository commit */ 127 | /* that brought the arduino repository up-to-date with */ 128 | /* the optiboot source tree changes since v3. */ 129 | /* */ 130 | /**********************************************************/ 131 | 132 | /**********************************************************/ 133 | /* Edit History: */ 134 | /* */ 135 | /* 4.4 WestfW: add initialization of address to keep */ 136 | /* the compiler happy. Change SC'ed targets. */ 137 | /* Return the SW version via READ PARAM */ 138 | /* 4.3 WestfW: catch framing errors in getch(), so that */ 139 | /* AVRISP works without HW kludges. */ 140 | /* http://code.google.com/p/arduino/issues/detail?id=368n*/ 141 | /* 4.2 WestfW: reduce code size, fix timeouts, change */ 142 | /* verifySpace to use WDT instead of appstart */ 143 | /* 4.1 WestfW: put version number in binary. */ 144 | /**********************************************************/ 145 | 146 | #define OPTIBOOT_MAJVER 4 147 | #define OPTIBOOT_MINVER 4 148 | 149 | #define MAKESTR(a) #a 150 | #define MAKEVER(a, b) MAKESTR(a*256+b) 151 | 152 | asm(" .section .version\n" 153 | "optiboot_version: .word " MAKEVER(OPTIBOOT_MAJVER, OPTIBOOT_MINVER) "\n" 154 | " .section .text\n"); 155 | 156 | #include 157 | #include 158 | #include 159 | 160 | // uses sts instructions, but this version uses out instructions 161 | // This saves cycles and program memory. 162 | #include "boot.h" 163 | 164 | 165 | #include 166 | 167 | 168 | // We don't use as those routines have interrupt overhead we don't need. 169 | 170 | #include "pin_defs.h" 171 | #include "stk500.h" 172 | 173 | #ifndef LED_START_FLASHES 174 | #define LED_START_FLASHES 0 175 | #endif 176 | 177 | #ifdef LUDICROUS_SPEED 178 | #define BAUD_RATE 230400L 179 | #endif 180 | 181 | /* set the UART baud rate defaults */ 182 | #ifndef BAUD_RATE 183 | #if F_CPU >= 8000000L 184 | #define BAUD_RATE 115200L // Highest rate Avrdude win32 will support 185 | #elsif F_CPU >= 1000000L 186 | #define BAUD_RATE 9600L // 19200 also supported, but with significant error 187 | #elsif F_CPU >= 128000L 188 | #define BAUD_RATE 4800L // Good for 128kHz internal RC 189 | #else 190 | #define BAUD_RATE 1200L // Good even at 32768Hz 191 | #endif 192 | #endif 193 | 194 | /* Switch in soft UART for hard baud rates */ 195 | 196 | // cchurch - added define to force hard UART, needed for nanoMoCo low baud rate 197 | #ifndef FORCE_HARD_UART 198 | #if (F_CPU/BAUD_RATE) > 280 // > 57600 for 16MHz 199 | #ifndef SOFT_UART 200 | #define SOFT_UART 201 | #endif 202 | #endif 203 | #endif 204 | 205 | /* Watchdog settings */ 206 | #define WATCHDOG_OFF (0) 207 | #define WATCHDOG_16MS (_BV(WDE)) 208 | #define WATCHDOG_32MS (_BV(WDP0) | _BV(WDE)) 209 | #define WATCHDOG_64MS (_BV(WDP1) | _BV(WDE)) 210 | #define WATCHDOG_125MS (_BV(WDP1) | _BV(WDP0) | _BV(WDE)) 211 | #define WATCHDOG_250MS (_BV(WDP2) | _BV(WDE)) 212 | #define WATCHDOG_500MS (_BV(WDP2) | _BV(WDP0) | _BV(WDE)) 213 | #define WATCHDOG_1S (_BV(WDP2) | _BV(WDP1) | _BV(WDE)) 214 | #define WATCHDOG_2S (_BV(WDP2) | _BV(WDP1) | _BV(WDP0) | _BV(WDE)) 215 | #ifndef __AVR_ATmega8__ 216 | #define WATCHDOG_4S (_BV(WDP3) | _BV(WDE)) 217 | #define WATCHDOG_8S (_BV(WDP3) | _BV(WDP0) | _BV(WDE)) 218 | #endif 219 | 220 | /* Function Prototypes */ 221 | /* The main function is in init9, which removes the interrupt vector table */ 222 | /* we don't need. It is also 'naked', which means the compiler does not */ 223 | /* generate any entry or exit code itself. */ 224 | int main(void) __attribute__ ((naked)) __attribute__ ((section (".init9"))); 225 | void putch(char); 226 | uint8_t getch(void); 227 | static inline void getNch(uint8_t); /* "static inline" is a compiler hint to reduce code size */ 228 | void verifySpace(); 229 | static inline void flash_led(uint8_t); 230 | uint8_t getLen(); 231 | static inline void watchdogReset(); 232 | void watchdogConfig(uint8_t x); 233 | #ifdef SOFT_UART 234 | void uartDelay() __attribute__ ((naked)); 235 | #endif 236 | void appStart() __attribute__ ((naked)); 237 | 238 | #if defined(__AVR_ATmega168__) 239 | #define RAMSTART (0x100) 240 | #define NRWWSTART (0x3800) 241 | #elif defined(__AVR_ATmega328P__) 242 | #define RAMSTART (0x100) 243 | #define NRWWSTART (0x7000) 244 | #elif defined (__AVR_ATmega644P__) 245 | #define RAMSTART (0x100) 246 | #define NRWWSTART (0xE000) 247 | #elif defined(__AVR_ATtiny84__) 248 | #define RAMSTART (0x100) 249 | #define NRWWSTART (0x0000) 250 | #elif defined(__AVR_ATmega1280__) 251 | #define RAMSTART (0x200) 252 | #define NRWWSTART (0xE000) 253 | #elif defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__) 254 | #define RAMSTART (0x100) 255 | #define NRWWSTART (0x1800) 256 | #endif 257 | 258 | /* C zero initialises all global variables. However, that requires */ 259 | /* These definitions are NOT zero initialised, but that doesn't matter */ 260 | /* This allows us to drop the zero init code, saving us memory */ 261 | #define buff ((uint8_t*)(RAMSTART)) 262 | #ifdef VIRTUAL_BOOT_PARTITION 263 | #define rstVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+4)) 264 | #define wdtVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+6)) 265 | #endif 266 | 267 | /* main program starts here */ 268 | int main(void) { 269 | uint8_t ch; 270 | 271 | /* 272 | * Making these local and in registers prevents the need for initializing 273 | * them, and also saves space because code no longer stores to memory. 274 | * (initializing address keeps the compiler happy, but isn't really 275 | * necessary, and uses 4 bytes of flash.) 276 | */ 277 | register uint16_t address = 0; 278 | register uint8_t length; 279 | 280 | 281 | // After the zero init loop, this is the first code to run. 282 | // 283 | // This code makes the following assumptions: 284 | // SP points to RAMEND 285 | // r1 contains zero 286 | // 287 | // If not, uncomment the following instructions: 288 | // cli(); 289 | asm volatile ("clr __zero_reg__"); 290 | #ifdef __AVR_ATmega8__ 291 | SP=RAMEND; // This is done by hardware reset 292 | #endif 293 | 294 | // Adaboot no-wait mod 295 | ch = MCUSR; 296 | MCUSR = 0; 297 | 298 | // add check for power-on reset 299 | if (!(ch & _BV(EXTRF)) && !(ch & _BV(PORF)) ) appStart(); 300 | 301 | // cchurch - need this to trip DE pin on 302 | // transmit for RS485 303 | 304 | DDRD |= _BV(PORTD5); 305 | PORTD &= ~_BV(PORTD5); 306 | // PORTD |= _BV(PORTD5); 307 | 308 | 309 | #if LED_START_FLASHES > 0 310 | // Set up Timer 1 for timeout counter 311 | TCCR1B = _BV(CS12) | _BV(CS10); // div 1024 312 | #endif 313 | #ifndef SOFT_UART 314 | #ifdef __AVR_ATmega8__ 315 | UCSRA = _BV(U2X); //Double speed mode USART 316 | UCSRB = _BV(RXEN) | _BV(TXEN); // enable Rx & Tx 317 | UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); // config USART; 8N1 318 | UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 ); 319 | #else 320 | UCSR0A = _BV(U2X0); //Double speed mode USART0 321 | UCSR0B = _BV(RXEN0) | _BV(TXEN0); 322 | UCSR0C = _BV(UCSZ00) | _BV(UCSZ01); 323 | UBRR0L = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 ); 324 | #endif 325 | #endif 326 | 327 | // Set up watchdog to trigger after 500ms 328 | watchdogConfig(WATCHDOG_8S); 329 | 330 | /* Set LED pin as output */ 331 | LED_DDR |= _BV(LED); 332 | 333 | #ifdef SOFT_UART 334 | /* Set TX pin as output */ 335 | UART_DDR |= _BV(UART_TX_BIT); 336 | #endif 337 | 338 | #if LED_START_FLASHES > 0 339 | /* Flash onboard LED to signal entering of bootloader */ 340 | flash_led(LED_START_FLASHES * 2); 341 | #endif 342 | 343 | /* Forever loop */ 344 | for (;;) { 345 | /* get character from UART */ 346 | ch = getch(); 347 | 348 | if(ch == STK_GET_PARAMETER) { 349 | unsigned char which = getch(); 350 | verifySpace(); 351 | 352 | if (which == 0x82) { 353 | /* 354 | * Send optiboot version as "minor SW version" 355 | */ 356 | putch(OPTIBOOT_MINVER); 357 | } else if (which == 0x81) { 358 | putch(OPTIBOOT_MAJVER); 359 | } else { 360 | /* 361 | * GET PARAMETER returns a generic 0x03 reply for 362 | * other parameters - enough to keep Avrdude happy 363 | */ 364 | putch(0x03); 365 | } 366 | } 367 | else if(ch == STK_SET_DEVICE) { 368 | // SET DEVICE is ignored 369 | getNch(20); 370 | } 371 | else if(ch == STK_SET_DEVICE_EXT) { 372 | // SET DEVICE EXT is ignored 373 | getNch(5); 374 | } 375 | else if(ch == STK_LOAD_ADDRESS) { 376 | // LOAD ADDRESS 377 | uint16_t newAddress; 378 | newAddress = getch(); 379 | newAddress = (newAddress & 0xff) | (getch() << 8); 380 | #ifdef RAMPZ 381 | // Transfer top bit to RAMPZ 382 | RAMPZ = (newAddress & 0x8000) ? 1 : 0; 383 | #endif 384 | newAddress += newAddress; // Convert from word address to byte address 385 | address = newAddress; 386 | verifySpace(); 387 | } 388 | else if(ch == STK_UNIVERSAL) { 389 | // UNIVERSAL command is ignored 390 | getNch(4); 391 | 392 | 393 | putch(0x00); 394 | } 395 | /* Write memory, length is big endian and is in bytes */ 396 | else if(ch == STK_PROG_PAGE) { 397 | // PROGRAM PAGE - we support flash programming only, not EEPROM 398 | uint8_t *bufPtr; 399 | uint16_t addrPtr; 400 | 401 | 402 | getch(); /* getlen() */ 403 | length = getch(); 404 | getch(); 405 | 406 | // If we are in RWW section, immediately start page erase 407 | if (address < NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address); 408 | 409 | // While that is going on, read in page contents 410 | bufPtr = buff; 411 | do *bufPtr++ = getch(); 412 | while (--length); 413 | 414 | // If we are in NRWW section, page erase has to be delayed until now. 415 | // Todo: Take RAMPZ into account 416 | if (address >= NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address); 417 | 418 | // Read command terminator, start reply 419 | verifySpace(); 420 | 421 | // If only a partial page is to be programmed, the erase might not be complete. 422 | // So check that here 423 | boot_spm_busy_wait(); 424 | 425 | #ifdef VIRTUAL_BOOT_PARTITION 426 | if ((uint16_t)(void*)address == 0) { 427 | // This is the reset vector page. We need to live-patch the code so the 428 | // bootloader runs. 429 | // 430 | // Move RESET vector to WDT vector 431 | uint16_t vect = buff[0] | (buff[1]<<8); 432 | rstVect = vect; 433 | wdtVect = buff[8] | (buff[9]<<8); 434 | vect -= 4; // Instruction is a relative jump (rjmp), so recalculate. 435 | buff[8] = vect & 0xff; 436 | buff[9] = vect >> 8; 437 | 438 | // Add jump to bootloader at RESET vector 439 | buff[0] = 0x7f; 440 | buff[1] = 0xce; // rjmp 0x1d00 instruction 441 | } 442 | #endif 443 | 444 | // Copy buffer into programming buffer 445 | bufPtr = buff; 446 | addrPtr = (uint16_t)(void*)address; 447 | ch = SPM_PAGESIZE / 2; 448 | do { 449 | uint16_t a; 450 | a = *bufPtr++; 451 | a |= (*bufPtr++) << 8; 452 | __boot_page_fill_short((uint16_t)(void*)addrPtr,a); 453 | addrPtr += 2; 454 | } while (--ch); 455 | 456 | // Write from programming buffer 457 | __boot_page_write_short((uint16_t)(void*)address); 458 | boot_spm_busy_wait(); 459 | 460 | #if defined(RWWSRE) 461 | // Reenable read access to flash 462 | boot_rww_enable(); 463 | #endif 464 | 465 | } 466 | /* Read memory block mode, length is big endian. */ 467 | else if(ch == STK_READ_PAGE) { 468 | // READ PAGE - we only read flash 469 | getch(); /* getlen() */ 470 | length = getch(); 471 | getch(); 472 | 473 | verifySpace(); 474 | #ifdef VIRTUAL_BOOT_PARTITION 475 | do { 476 | // Undo vector patch in bottom page so verify passes 477 | if (address == 0) ch=rstVect & 0xff; 478 | else if (address == 1) ch=rstVect >> 8; 479 | else if (address == 8) ch=wdtVect & 0xff; 480 | else if (address == 9) ch=wdtVect >> 8; 481 | else ch = pgm_read_byte_near(address); 482 | address++; 483 | putch(ch); 484 | } while (--length); 485 | #else 486 | #ifdef __AVR_ATmega1280__ 487 | // do putch(pgm_read_byte_near(address++)); 488 | // while (--length); 489 | do { 490 | uint8_t result; 491 | __asm__ ("elpm %0,Z\n":"=r"(result):"z"(address)); 492 | putch(result); 493 | address++; 494 | } 495 | while (--length); 496 | #else 497 | do putch(pgm_read_byte_near(address++)); 498 | while (--length); 499 | #endif 500 | #endif 501 | } 502 | 503 | /* Get device signature bytes */ 504 | else if(ch == STK_READ_SIGN) { 505 | // READ SIGN - return what Avrdude wants to hear 506 | verifySpace(); 507 | putch(SIGNATURE_0); 508 | putch(SIGNATURE_1); 509 | putch(SIGNATURE_2); 510 | } 511 | else if (ch == 'Q') { 512 | // Adaboot no-wait mod 513 | watchdogConfig(WATCHDOG_16MS); 514 | verifySpace(); 515 | } 516 | else { 517 | // This covers the response to commands like STK_ENTER_PROGMODE 518 | verifySpace(); 519 | } 520 | putch(STK_OK); 521 | } 522 | } 523 | 524 | void putch(char ch) { 525 | #ifndef SOFT_UART 526 | 527 | 528 | 529 | LED_PIN |= _BV(LED); 530 | 531 | while (!(UCSR0A & _BV(UDRE0))); 532 | 533 | PORTD |= _BV(PORTD5); 534 | 535 | UCSR0A |= _BV(TXC0); 536 | 537 | UDR0 = ch; 538 | 539 | 540 | while(!(UCSR0A & _BV(TXC0)) ); 541 | 542 | _delay_us(8.75); 543 | 544 | PORTD &= ~_BV(PORTD5); 545 | 546 | LED_PIN &= ~_BV(LED); 547 | 548 | #else 549 | 550 | __asm__ __volatile__ ( 551 | " com %[ch]\n" // ones complement, carry set 552 | " sec\n" 553 | "1: brcc 2f\n" 554 | " cbi %[uartPort],%[uartBit]\n" 555 | " rjmp 3f\n" 556 | "2: sbi %[uartPort],%[uartBit]\n" 557 | " nop\n" 558 | "3: rcall uartDelay\n" 559 | " rcall uartDelay\n" 560 | " lsr %[ch]\n" 561 | " dec %[bitcnt]\n" 562 | " brne 1b\n" 563 | : 564 | : 565 | [bitcnt] "d" (10), 566 | [ch] "r" (ch), 567 | [uartPort] "I" (_SFR_IO_ADDR(UART_PORT)), 568 | [uartBit] "I" (UART_TX_BIT) 569 | : 570 | "r25" 571 | ); 572 | 573 | #endif 574 | } 575 | 576 | uint8_t getch(void) { 577 | uint8_t ch; 578 | 579 | 580 | 581 | #ifdef LED_DATA_FLASH 582 | #ifdef __AVR_ATmega8__ 583 | LED_PORT ^= _BV(LED); 584 | #else 585 | LED_PIN |= _BV(LED); 586 | #endif 587 | #endif 588 | 589 | #ifdef SOFT_UART 590 | __asm__ __volatile__ ( 591 | "1: sbic %[uartPin],%[uartBit]\n" // Wait for start edge 592 | " rjmp 1b\n" 593 | " rcall uartDelay\n" // Get to middle of start bit 594 | "2: rcall uartDelay\n" // Wait 1 bit period 595 | " rcall uartDelay\n" // Wait 1 bit period 596 | " clc\n" 597 | " sbic %[uartPin],%[uartBit]\n" 598 | " sec\n" 599 | " dec %[bitCnt]\n" 600 | " breq 3f\n" 601 | " ror %[ch]\n" 602 | " rjmp 2b\n" 603 | "3:\n" 604 | : 605 | [ch] "=r" (ch) 606 | : 607 | [bitCnt] "d" (9), 608 | [uartPin] "I" (_SFR_IO_ADDR(UART_PIN)), 609 | [uartBit] "I" (UART_RX_BIT) 610 | : 611 | "r25" 612 | ); 613 | #else 614 | 615 | while(!(UCSR0A & _BV(RXC0))) 616 | ; 617 | if (!(UCSR0A & _BV(FE0))) { 618 | /* 619 | * A Framing Error indicates (probably) that something is talking 620 | * to us at the wrong bit rate. Assume that this is because it 621 | * expects to be talking to the application, and DON'T reset the 622 | * watchdog. This should cause the bootloader to abort and run 623 | * the application "soon", if it keeps happening. (Note that we 624 | * don't care that an invalid char is returned...) 625 | */ 626 | watchdogReset(); 627 | } 628 | 629 | ch = UDR0; 630 | 631 | 632 | #endif 633 | 634 | #ifdef LED_DATA_FLASH 635 | #ifdef __AVR_ATmega8__ 636 | LED_PORT ^= _BV(LED); 637 | #else 638 | LED_PIN |= _BV(LED); 639 | #endif 640 | #endif 641 | 642 | return ch; 643 | } 644 | 645 | #ifdef SOFT_UART 646 | // AVR350 equation: #define UART_B_VALUE (((F_CPU/BAUD_RATE)-23)/6) 647 | // Adding 3 to numerator simulates nearest rounding for more accurate baud rates 648 | #define UART_B_VALUE (((F_CPU/BAUD_RATE)-20)/6) 649 | #if UART_B_VALUE > 255 650 | #error Baud rate too slow for soft UART 651 | #endif 652 | 653 | void uartDelay() { 654 | __asm__ __volatile__ ( 655 | "ldi r25,%[count]\n" 656 | "1:dec r25\n" 657 | "brne 1b\n" 658 | "ret\n" 659 | ::[count] "M" (UART_B_VALUE) 660 | ); 661 | } 662 | #endif 663 | 664 | void getNch(uint8_t count) { 665 | do getch(); while (--count); 666 | verifySpace(); 667 | } 668 | 669 | void verifySpace() { 670 | if (getch() != CRC_EOP) { 671 | watchdogConfig(WATCHDOG_16MS); // shorten WD timeout 672 | while (1) // and busy-loop so that WD causes 673 | ; // a reset and app start. 674 | } 675 | putch(STK_INSYNC); 676 | } 677 | 678 | #if LED_START_FLASHES > 0 679 | void flash_led(uint8_t count) { 680 | do { 681 | TCNT1 = -(F_CPU/(1024*16)); 682 | TIFR1 = _BV(TOV1); 683 | while(!(TIFR1 & _BV(TOV1))); 684 | #ifdef __AVR_ATmega8__ 685 | LED_PORT ^= _BV(LED); 686 | #else 687 | LED_PIN |= _BV(LED); 688 | #endif 689 | watchdogReset(); 690 | } while (--count); 691 | } 692 | #endif 693 | 694 | // Watchdog functions. These are only safe with interrupts turned off. 695 | void watchdogReset() { 696 | __asm__ __volatile__ ( 697 | "wdr\n" 698 | ); 699 | } 700 | 701 | void watchdogConfig(uint8_t x) { 702 | WDTCSR = _BV(WDCE) | _BV(WDE); 703 | WDTCSR = x; 704 | } 705 | 706 | void appStart() { 707 | watchdogConfig(WATCHDOG_OFF); 708 | __asm__ __volatile__ ( 709 | #ifdef VIRTUAL_BOOT_PARTITION 710 | // Jump to WDT vector 711 | "ldi r30,4\n" 712 | "clr r31\n" 713 | #else 714 | // Jump to RST vector 715 | "clr r30\n" 716 | "clr r31\n" 717 | #endif 718 | "ijmp\n" 719 | ); 720 | } 721 | -------------------------------------------------------------------------------- /Bootloader/hardware/arduino/bootloaders/optiboot/pin_defs.h: -------------------------------------------------------------------------------- 1 | #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__) 2 | /* Onboard LED is connected to pin PB5 in Arduino NG, Diecimila, and Duemilanove */ 3 | #define LED_DDR DDRB 4 | #define LED_PORT PORTB 5 | #define LED_PIN PINB 6 | #define LED PINB5 7 | 8 | /* Ports for soft UART */ 9 | #ifdef SOFT_UART 10 | #define UART_PORT PORTD 11 | #define UART_PIN PIND 12 | #define UART_DDR DDRD 13 | #define UART_TX_BIT 1 14 | #define UART_RX_BIT 0 15 | #endif 16 | #endif 17 | 18 | #if defined(__AVR_ATmega8__) 19 | //Name conversion R.Wiersma 20 | #define UCSR0A UCSRA 21 | #define UDR0 UDR 22 | #define UDRE0 UDRE 23 | #define RXC0 RXC 24 | #define FE0 FE 25 | #define TIFR1 TIFR 26 | #define WDTCSR WDTCR 27 | #endif 28 | 29 | /* Luminet support */ 30 | #if defined(__AVR_ATtiny84__) 31 | /* Red LED is connected to pin PA4 */ 32 | #define LED_DDR DDRA 33 | #define LED_PORT PORTA 34 | #define LED_PIN PINA 35 | #define LED PINA4 36 | /* Ports for soft UART - left port only for now. TX/RX on PA2/PA3 */ 37 | #ifdef SOFT_UART 38 | #define UART_PORT PORTA 39 | #define UART_PIN PINA 40 | #define UART_DDR DDRA 41 | #define UART_TX_BIT 2 42 | #define UART_RX_BIT 3 43 | #endif 44 | #endif 45 | 46 | /* Sanguino support */ 47 | #if defined(__AVR_ATmega644P__) 48 | /* Onboard LED is connected to pin PB0 on Sanguino */ 49 | #define LED_DDR DDRB 50 | #define LED_PORT PORTB 51 | #define LED_PIN PINB 52 | #define LED PINB0 53 | 54 | /* Ports for soft UART */ 55 | #ifdef SOFT_UART 56 | #define UART_PORT PORTD 57 | #define UART_PIN PIND 58 | #define UART_DDR DDRD 59 | #define UART_TX_BIT 1 60 | #define UART_RX_BIT 0 61 | #endif 62 | #endif 63 | 64 | /* Mega support */ 65 | #if defined(__AVR_ATmega1280__) 66 | /* Onboard LED is connected to pin PB7 on Arduino Mega */ 67 | #define LED_DDR DDRB 68 | #define LED_PORT PORTB 69 | #define LED_PIN PINB 70 | #define LED PINB7 71 | 72 | /* Ports for soft UART */ 73 | #ifdef SOFT_UART 74 | #define UART_PORT PORTE 75 | #define UART_PIN PINE 76 | #define UART_DDR DDRE 77 | #define UART_TX_BIT 1 78 | #define UART_RX_BIT 0 79 | #endif 80 | #endif 81 | -------------------------------------------------------------------------------- /Bootloader/hardware/arduino/bootloaders/optiboot/stk500.h: -------------------------------------------------------------------------------- 1 | /* STK500 constants list, from AVRDUDE */ 2 | #define STK_OK 0x10 3 | #define STK_FAILED 0x11 // Not used 4 | #define STK_UNKNOWN 0x12 // Not used 5 | #define STK_NODEVICE 0x13 // Not used 6 | #define STK_INSYNC 0x14 // ' ' 7 | #define STK_NOSYNC 0x15 // Not used 8 | #define ADC_CHANNEL_ERROR 0x16 // Not used 9 | #define ADC_MEASURE_OK 0x17 // Not used 10 | #define PWM_CHANNEL_ERROR 0x18 // Not used 11 | #define PWM_ADJUST_OK 0x19 // Not used 12 | #define CRC_EOP 0x20 // 'SPACE' 13 | #define STK_GET_SYNC 0x30 // '0' 14 | #define STK_GET_SIGN_ON 0x31 // '1' 15 | #define STK_SET_PARAMETER 0x40 // '@' 16 | #define STK_GET_PARAMETER 0x41 // 'A' 17 | #define STK_SET_DEVICE 0x42 // 'B' 18 | #define STK_SET_DEVICE_EXT 0x45 // 'E' 19 | #define STK_ENTER_PROGMODE 0x50 // 'P' 20 | #define STK_LEAVE_PROGMODE 0x51 // 'Q' 21 | #define STK_CHIP_ERASE 0x52 // 'R' 22 | #define STK_CHECK_AUTOINC 0x53 // 'S' 23 | #define STK_LOAD_ADDRESS 0x55 // 'U' 24 | #define STK_UNIVERSAL 0x56 // 'V' 25 | #define STK_PROG_FLASH 0x60 // '`' 26 | #define STK_PROG_DATA 0x61 // 'a' 27 | #define STK_PROG_FUSE 0x62 // 'b' 28 | #define STK_PROG_LOCK 0x63 // 'c' 29 | #define STK_PROG_PAGE 0x64 // 'd' 30 | #define STK_PROG_FUSE_EXT 0x65 // 'e' 31 | #define STK_READ_FLASH 0x70 // 'p' 32 | #define STK_READ_DATA 0x71 // 'q' 33 | #define STK_READ_FUSE 0x72 // 'r' 34 | #define STK_READ_LOCK 0x73 // 's' 35 | #define STK_READ_PAGE 0x74 // 't' 36 | #define STK_READ_SIGN 0x75 // 'u' 37 | #define STK_READ_OSCCAL 0x76 // 'v' 38 | #define STK_READ_FUSE_EXT 0x77 // 'w' 39 | #define STK_READ_OSCCAL_EXT 0x78 // 'x' 40 | -------------------------------------------------------------------------------- /Firmware/Motion_Engine/Debug.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | #include "Debug.h" 6 | 7 | DebugClass::DebugClass(OMMoCoPrintClass *c_mocoPrint){ 8 | m_mocoPrint = c_mocoPrint; 9 | init(); 10 | } 11 | 12 | void DebugClass::init() 13 | { 14 | /* 15 | Initialize the debug flag to no reporting and 16 | ensure both the debug output lines are off 17 | */ 18 | m_debug_flag = B00000000; 19 | m_usb = false; 20 | m_moco = false; 21 | } 22 | 23 | void DebugClass::setState(byte state){ 24 | m_debug_flag = state; 25 | const char *message = "New debug flag state: "; 26 | if (m_usb){ 27 | USBSerial.print(message); 28 | USBSerial.println(state, BIN); 29 | USBSerial.println(""); 30 | } 31 | if (m_moco){ 32 | m_mocoPrint->print(message); 33 | m_mocoPrint->println(state, BIN); 34 | m_mocoPrint->println(""); 35 | } 36 | } 37 | 38 | byte DebugClass::getState(){ 39 | return m_debug_flag; 40 | } 41 | 42 | bool DebugClass::setUSB(bool enabled){ 43 | m_usb = enabled; 44 | return m_usb; 45 | } 46 | bool DebugClass::getUSB(){ 47 | return m_usb; 48 | } 49 | 50 | bool DebugClass::setMoco(bool enabled){ 51 | m_moco = enabled; 52 | return m_moco; 53 | } 54 | bool DebugClass::getMoco(){ 55 | return m_moco; 56 | } 57 | -------------------------------------------------------------------------------- /Firmware/Motion_Engine/Debug.h: -------------------------------------------------------------------------------- 1 | // Debug.h 2 | 3 | #ifndef _DEBUG_h 4 | #define _DEBUG_h 5 | 6 | #if defined(ARDUINO) && ARDUINO >= 100 7 | #include "Arduino.h" 8 | #else 9 | #include "WProgram.h" 10 | #endif 11 | 12 | #include "OMMoCoPrint.h" 13 | 14 | class DebugClass 15 | { 16 | private: 17 | void init(); 18 | byte m_debug_flag; // Byte holding debug output flags 19 | bool m_usb; 20 | bool m_moco; 21 | OMMoCoPrintClass *m_mocoPrint; 22 | 23 | public: 24 | DebugClass(OMMoCoPrintClass *c_mocoPrint); 25 | const static byte DB_COM_OUT = B00000001; // Debug flag -- toggles output of received serial commands 26 | const static byte DB_STEPS = B00000010; // Debug flag -- toggles output of motor step information 27 | const static byte DB_MOTOR = B00000100; // Debug flag -- toggles output of general motor information 28 | const static byte DB_GEN_SER = B00001000; // Debug flag -- toggles output of responses to certain serial commands 29 | const static byte DB_FUNCT = B00010000; // Debug flag -- toggles output of debug messages within most functions 30 | const static byte DB_CONFIRM = B00100000; // Debug flag -- toggles output of success and failure messages in response to serial commands 31 | 32 | void setState(byte state); 33 | byte getState(); 34 | 35 | bool setUSB(bool enabled); 36 | bool getUSB(); 37 | 38 | bool setMoco(bool enabled); 39 | bool getMoco(); 40 | 41 | template 42 | void ser(T data){ 43 | if (m_debug_flag & DB_GEN_SER){ 44 | if (m_usb) 45 | USBSerial.print(data); 46 | if (m_moco) 47 | m_mocoPrint->print(data); 48 | } 49 | } 50 | 51 | template 52 | void serln(T data){ 53 | if (m_debug_flag & DB_GEN_SER){ 54 | if (m_usb) 55 | USBSerial.println(data); 56 | if (m_moco) 57 | m_mocoPrint->println(data); 58 | } 59 | } 60 | 61 | template 62 | void funct(T data){ 63 | if (m_debug_flag & DB_FUNCT){ 64 | if (m_usb) 65 | USBSerial.print(data); 66 | if (m_moco) 67 | m_mocoPrint->print(data); 68 | } 69 | } 70 | 71 | template 72 | void functln(T data){ 73 | if (m_debug_flag & DB_FUNCT){ 74 | if (m_usb) 75 | USBSerial.println(data); 76 | if (m_moco) 77 | m_mocoPrint->println(data); 78 | } 79 | } 80 | 81 | template 82 | void com(T data){ 83 | if (m_debug_flag & DB_COM_OUT){ 84 | if (m_usb) 85 | USBSerial.print(data); 86 | if (m_moco) 87 | m_mocoPrint->print(data); 88 | } 89 | } 90 | 91 | template 92 | void comln(T data){ 93 | if (m_debug_flag & DB_COM_OUT){ 94 | if (m_usb) 95 | USBSerial.println(data); 96 | if (m_moco) 97 | m_mocoPrint->println(data); 98 | } 99 | } 100 | 101 | template 102 | void com(T data, int base){ 103 | if (m_debug_flag & DB_COM_OUT){ 104 | if (m_usb) 105 | USBSerial.print(data, base); 106 | if (m_moco) 107 | m_mocoPrint->print(data, base); 108 | } 109 | } 110 | 111 | template 112 | void comln(T data, int base){ 113 | if (m_debug_flag & DB_COM_OUT){ 114 | if (m_usb) 115 | USBSerial.println(data, base); 116 | if (m_moco) 117 | m_mocoPrint->println(data, base); 118 | } 119 | } 120 | 121 | template 122 | void confirm(T data){ 123 | if (m_debug_flag & DB_CONFIRM){ 124 | if (m_usb) 125 | USBSerial.print(data); 126 | if (m_moco) 127 | m_mocoPrint->print(data); 128 | } 129 | } 130 | 131 | template 132 | void confirmln(T data){ 133 | if (m_debug_flag & DB_CONFIRM){ 134 | if (m_usb) 135 | USBSerial.println(data); 136 | if (m_moco) 137 | m_mocoPrint->println(data); 138 | } 139 | } 140 | 141 | template 142 | void steps(T data){ 143 | if (m_debug_flag & DB_STEPS){ 144 | if (m_usb) 145 | USBSerial.print(data); 146 | if (m_moco) 147 | m_mocoPrint->print(data); 148 | } 149 | } 150 | 151 | template 152 | void stepsln(T data){ 153 | if (m_debug_flag & DB_STEPS){ 154 | if (m_usb) 155 | USBSerial.println(data); 156 | if (m_moco) 157 | m_mocoPrint->println(data); 158 | } 159 | } 160 | }; 161 | #endif 162 | 163 | -------------------------------------------------------------------------------- /Firmware/Motion_Engine/LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | -------------------------------------------------------------------------------- /Firmware/Motion_Engine/MotionEngineProtocol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DynamicPerception/nanoMoCo_Firmware/7577e212ca9723c52d375a32c20482f551d35fb3/Firmware/Motion_Engine/MotionEngineProtocol.pdf -------------------------------------------------------------------------------- /Firmware/Motion_Engine/NMX Commands 0.12.1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DynamicPerception/nanoMoCo_Firmware/7577e212ca9723c52d375a32c20482f551d35fb3/Firmware/Motion_Engine/NMX Commands 0.12.1.pdf -------------------------------------------------------------------------------- /Firmware/Motion_Engine/NMX Commands 0.13 w-data types.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DynamicPerception/nanoMoCo_Firmware/7577e212ca9723c52d375a32c20482f551d35fb3/Firmware/Motion_Engine/NMX Commands 0.13 w-data types.pdf -------------------------------------------------------------------------------- /Firmware/Motion_Engine/NMX Commands.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DynamicPerception/nanoMoCo_Firmware/7577e212ca9723c52d375a32c20482f551d35fb3/Firmware/Motion_Engine/NMX Commands.ods -------------------------------------------------------------------------------- /Firmware/Motion_Engine/NMX Commands.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DynamicPerception/nanoMoCo_Firmware/7577e212ca9723c52d375a32c20482f551d35fb3/Firmware/Motion_Engine/NMX Commands.pdf -------------------------------------------------------------------------------- /Firmware/Motion_Engine/OMMoCoPrint.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | #include "OMMoCoPrint.h" 6 | 7 | OMMoCoPrintClass::OMMoCoPrintClass(OMMoCoNode *node){ 8 | m_node = node; 9 | } 10 | 11 | void OMMoCoPrintClass::init() 12 | { 13 | 14 | 15 | } 16 | 17 | size_t OMMoCoPrintClass::write(uint8_t data){ 18 | m_node->write(data); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Firmware/Motion_Engine/OMMoCoPrint.h: -------------------------------------------------------------------------------- 1 | // OMMoCoPrint.h 2 | 3 | #ifndef _OMMOCOPRINT_h 4 | #define _OMMOCOPRINT_h 5 | 6 | #if defined(ARDUINO) && ARDUINO >= 100 7 | #include "Arduino.h" 8 | #else 9 | #include "WProgram.h" 10 | #endif 11 | #include "OMMoCoNode.h" 12 | 13 | class OMMoCoPrintClass : public Print 14 | { 15 | private: 16 | OMMoCoNode *m_node; 17 | 18 | protected: 19 | 20 | 21 | public: 22 | OMMoCoPrintClass(OMMoCoNode *node); 23 | void init(); 24 | virtual size_t write(uint8_t); 25 | }; 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /Firmware/Motion_Engine/OM_CameraMaster.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Camera Functionality Library 4 | 5 | OpenMoco MoCoBus Core Libraries 6 | 7 | See www.dynamicperception.com for more information 8 | 9 | (c) 2008-2012 C.A. Church / Dynamic Perception LLC 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program. If not, see . 23 | 24 | 25 | */ 26 | /* 27 | void stopAllCameras() { 28 | 29 | // stop timer (always) 30 | // we do this before bringing the pin low in case 31 | // a VERY short action time was set to prevent the 32 | // timer from continuing to trigger and getting stuck in 33 | // a loop. 34 | 35 | MsTimer2::stop(); 36 | camera[0].stop(); 37 | camera[1].stop(); 38 | 39 | } 40 | 41 | 42 | /** Trigger Exposure 43 | 44 | This method triggers an exposure for the amount of time as set via triggerTime(). 45 | Sends an expose begin signal. 46 | 47 | */ 48 | 49 | /* 50 | 51 | void exposeAll() { 52 | camera[0].expose(); 53 | camera[1].expose(); 54 | } 55 | 56 | /** Trigger Exposure 57 | 58 | This method triggers an exposure for the amount of time specified. 59 | Sends an expose begin signal. 60 | 61 | @param p_Time 62 | Length (in milliseconds) of the exposure. 63 | 64 | */ 65 | /* 66 | void expose(unsigned long p_time) { 67 | 68 | // do not expose if exposure time is zero 69 | if( p_time == 0 ) { 70 | if( f_camSignal != 0 ) 71 | f_camSignal(OM_CAM_EFIN); 72 | 73 | return; 74 | } 75 | // indicate (for stop()), that we are in an exposure 76 | // to properly set output states when timer2 completes 77 | 78 | m_curAct = OM_CAM_INEXP; 79 | 80 | 81 | // determine if focus pin should be brought high 82 | // w. the shutter pin (for some nikons, etc.) 83 | 84 | if( m_focusShut == true ) 85 | digitalWrite(m_focus, HIGH); 86 | 87 | digitalWrite(m_shutter, HIGH); 88 | 89 | // start timer to stop camera exposure 90 | MsTimer2::set(p_time, OMCameraFunction::stop); 91 | MsTimer2::start(); 92 | 93 | 94 | // update camera currently engaged 95 | m_isBzy = true; 96 | 97 | 98 | // if there is a pointer to a function 99 | // to be called when the camera is done, 100 | // do it now 101 | 102 | if( f_camSignal != 0 ) 103 | f_camSignal(OM_CAMEXP); 104 | 105 | return; 106 | } 107 | 108 | 109 | /** Trigger Focus 110 | 111 | This method triggers a focus for the amount of time as set via focusTime(). 112 | Sends a focus begin signal. 113 | 114 | */ 115 | /* 116 | void focus() { 117 | this->focus(m_timeFoc); 118 | } 119 | 120 | /** Trigger Focus 121 | 122 | This method triggers a focus for the amount of time specified. 123 | Sends a focus begin signal. 124 | 125 | @param p_Time 126 | Length (in milliseconds) of the focus. 127 | 128 | */ 129 | /* 130 | void focus(unsigned int p_time) { 131 | 132 | // do not focus if focus time is 0 133 | if( p_time == 0 ) { 134 | if( f_camSignal != 0 ) 135 | f_camSignal(OM_CAM_FFIN); 136 | 137 | return; 138 | } 139 | 140 | digitalWrite(m_focus, HIGH); 141 | 142 | // start timer to stop focus engage 143 | 144 | m_curAct = OM_CAM_INFOC; 145 | 146 | MsTimer2::set(p_time, OMCameraFunction::stop); 147 | MsTimer2::start(); 148 | // update camera currently engaged 149 | m_isBzy = true; 150 | // report focus in progress 151 | if( f_camSignal != 0 ) 152 | f_camSignal(OM_CAMFOC); 153 | 154 | } 155 | 156 | 157 | /** Trigger Delay 158 | 159 | This method triggers a delay action for the amount of time specified. 160 | Sends a delay begin signal. 161 | 162 | @param p_Time 163 | Length (in milliseconds) of the delay. 164 | 165 | */ 166 | /* 167 | void cameraWait(unsigned int p_Time) { 168 | 169 | // do not wait, if wait time is 0 170 | if( p_Time == 0 ) { 171 | if( f_camSignal != 0 ) 172 | f_camSignal(OM_CAM_WFIN); 173 | 174 | return; 175 | } 176 | 177 | m_curAct = OM_CAM_INDLY; 178 | 179 | MsTimer2::set(p_Time, OMCameraFunction::stop); 180 | MsTimer2::start(); 181 | 182 | // update camera currently engaged 183 | m_isBzy = true; 184 | 185 | if( f_camSignal != 0 ) 186 | f_camSignal(OM_CAMWAIT); 187 | } 188 | 189 | -------------------------------------------------------------------------------- /Firmware/Motion_Engine/OM_Camera_Control.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | Motion Engine 5 | 6 | See dynamicperception.com for more information 7 | 8 | 9 | (c) 2008-2012 C.A. Church / Dynamic Perception LLC 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program. If not, see . 23 | 24 | 25 | */ 26 | 27 | /* 28 | 29 | ======================================== 30 | Camera control functions 31 | ======================================== 32 | 33 | */ 34 | 35 | 36 | 37 | uint8_t oldProgramMode; 38 | 39 | void camExpose() { 40 | 41 | // what to do when camera focus is complete? 42 | 43 | // state to block must happen before call to expose() 44 | Engine.state(ST_BLOCK); // block further activity until exposure is done 45 | Camera.expose(); 46 | } 47 | 48 | void camWait() { 49 | 50 | // what to do when camera exposure is complete? 51 | 52 | 53 | // state to block must happen before call to wait() 54 | Engine.state(ST_BLOCK); // block further activity until post delay is done 55 | Camera.wait(); 56 | } 57 | 58 | 59 | void camCallBack(byte code) { 60 | 61 | // This callback is called whenever an asynchronous activity begins or ends, and 62 | // is able to take some actions as different states are reported out of the 63 | // camera object. 64 | // 65 | // We only care about when certain activities complete, so that's what we look for.. 66 | // 67 | // Do NOT attempt to use delay() here, or call another camera action directly, as this 68 | // function is called in an interrupt and can daisy-chain under certain configurations, 69 | // which can result in unexpected behavior 70 | 71 | if( code == OM_CAM_FFIN ) { 72 | debug.functln("camCallBack() - Start"); 73 | Engine.state(ST_EXP); 74 | } 75 | else if( code == OM_CAM_EFIN ) { 76 | debug.functln("camCallBack() - Stop"); 77 | camera_fired++; 78 | Engine.state(ST_WAIT); 79 | } 80 | else if( code == OM_CAM_WFIN ) { 81 | // we may have exposure repeat cycle to manage 82 | // after the post-exposure delay 83 | checkCameraRepeat(); 84 | } 85 | 86 | 87 | } 88 | 89 | // check for camera repeat cycle 90 | void checkCameraRepeat() { 91 | 92 | 93 | static byte repdone = 0; 94 | 95 | // if we don't have camera repeat function enabled, 96 | // then go ahead and clear for alt out post shot check 97 | if( Camera.repeat == 0 ) { 98 | Engine.state(ST_ALTP); 99 | return; 100 | } 101 | 102 | if( repdone >= Camera.repeat ) { 103 | // we've done all of the repeat cycles 104 | repdone = 0; 105 | // clear for check post-exposure alt output trigger 106 | Engine.state(ST_ALTP); 107 | return; 108 | } 109 | 110 | // trigger another exposure 111 | repdone++; 112 | Engine.state(ST_EXP); 113 | } 114 | 115 | /** 116 | Start or stop camera test mode 117 | */ 118 | void cameraTest(uint8_t p_start) { 119 | 120 | // If the command doesn't change the test mode, ignore it and exit the fucntion 121 | if (camera_test_mode == p_start) 122 | return; 123 | 124 | Camera.enable = true; 125 | static uint8_t old_enable[MOTOR_COUNT]; 126 | static unsigned long old_max_shots; 127 | camera_test_mode = p_start; 128 | 129 | // Entering test mode 130 | if (camera_test_mode) { 131 | 132 | // Save current program type, then switch to SMS mode 133 | oldProgramMode = Motors::planType(); 134 | Motors::planType(SMS); 135 | 136 | // Remember each motor's enable mode and disable all of them 137 | for (byte i = 0; i < MOTOR_COUNT; i++) { 138 | old_enable[i] = motor[i].enable(); 139 | motor[i].enable(false); 140 | } 141 | 142 | // Remember the current max shots setting 143 | old_max_shots = Camera.getMaxShots(); 144 | 145 | // Set the max shots to an arbitrarily large value so the test mode doesn't stop 146 | Camera.setMaxShots(10000); 147 | 148 | // Starting the program will make the camera fire, but the motors won't move 149 | startProgram(); 150 | 151 | } 152 | 153 | // Exiting test mode 154 | else if (!camera_test_mode) { 155 | 156 | // Stop the camera firing 157 | stopProgram(); 158 | 159 | // Restore motor enable statuses and camera max shots 160 | for (byte i = 0; i < MOTOR_COUNT; i++) 161 | motor[i].enable(old_enable[i]); 162 | 163 | Camera.setMaxShots(old_max_shots); 164 | 165 | // Reset the shot count to 0 166 | camera_fired = 0; 167 | 168 | // Restore old program type 169 | Motors::planType(oldProgramMode); 170 | } 171 | } 172 | 173 | 174 | /** 175 | 176 | Return whether the camera is in test mode 177 | 178 | */ 179 | uint8_t cameraTest() { 180 | 181 | return(camera_test_mode); 182 | 183 | } 184 | 185 | 186 | /** 187 | 188 | Automatically sets the max shots value based upon the lead-in, travel, and lead-out shots. 189 | 190 | */ 191 | void cameraAutoMaxShots() { 192 | 193 | // This function should only be used with SMS mode, since leads and travel are in milliseconds for CONT_TL and CONT_VID 194 | if (Motors::planType() != SMS) 195 | return; 196 | 197 | unsigned int longest = 0; 198 | unsigned int current = 0; 199 | 200 | // Find the longest combination of leads and travel, then set that as the max shots 201 | for (byte i = 0; i < MOTOR_COUNT; i++) { 202 | current = motor[i].planLeadIn() + motor[i].planTravelLength() + motor[i].planLeadOut(); 203 | if (current > longest) 204 | longest = current; 205 | } 206 | 207 | Camera.setMaxShots(longest); 208 | } 209 | 210 | // Returns the total number of shots from the current program pass, plus any previous passes 211 | unsigned int getTotalShots(){ 212 | if (!running && !kf_running) 213 | return 0; 214 | else 215 | return camera_fired + ping_pong_shots; 216 | } 217 | 218 | // Clears shot counters 219 | void clearShotCounter(){ 220 | camera_fired = 0; 221 | ping_pong_shots = 0; 222 | } 223 | 224 | 225 | 226 | 227 | 228 | -------------------------------------------------------------------------------- /Firmware/Motion_Engine/OM_ControlCycle.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Motion Engine 4 | 5 | See dynamicperception.com for more information 6 | 7 | 8 | (c) 2008-2012 C.A. Church / Dynamic Perception LLC 9 | 10 | This program is free software: you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation, either version 3 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program. If not, see . 22 | 23 | 24 | */ 25 | 26 | /* 27 | 28 | ======================================== 29 | Main Timing Cycle functions - initialize StateEngine (OMState) 30 | ======================================== 31 | 32 | */ 33 | 34 | 35 | unsigned long camera_tm = 0; 36 | byte altBlock = 0; 37 | 38 | 39 | void setupControlCycle() { 40 | 41 | Engine.setHandler(ST_CLEAR, cycleCamera); 42 | Engine.setHandler(ST_MOVE, cycleClearToMove); 43 | Engine.setHandler(ST_RUN, cycleCheckMotor); 44 | Engine.setHandler(ST_EXP, camExpose); 45 | Engine.setHandler(ST_WAIT, camWait); 46 | Engine.setHandler(ST_ALTP, cycleCheckAltPost); 47 | } 48 | 49 | 50 | 51 | void cycleCamera() { 52 | const String CYCLE_CAMERA = "cycleCamera() - "; 53 | debug.functln(CYCLE_CAMERA + "Start"); 54 | 55 | // Check to see if a pause was requested. The program is paused here to avoid unexpected stops in the middle of a move or exposure. 56 | if (pause_flag) { 57 | debug.functln(CYCLE_CAMERA + "Pausing"); 58 | pauseProgram(); 59 | } 60 | 61 | 62 | // Determine whether the critera for denoting a completed SMS or continuous program have been met 63 | bool sms_done = false; 64 | bool continuous_done = false; 65 | if (Motors::planType() == SMS) 66 | sms_done = Camera.getMaxShots() > 0 && camera_fired > Camera.getMaxShots(); 67 | else if (Motors::planType() != SMS){ 68 | continuous_done = true; 69 | for (byte i = 0; i < MOTOR_COUNT; i++){ 70 | if (!motor[i].programDone()) 71 | continuous_done = false; 72 | } 73 | } 74 | 75 | /* 76 | * Stop program if max shots exceeded or if the continuous TL/video program as reached its destination. 77 | * The program stops when camera_fired exceeds Camera.maxShots instead of equalling it in order to allow the camera to take an exposure at its final destination. 78 | * If the keep_camera_alive variable is true, then the program will not stop (i.e. the camera will continue shooting) until the program is manually stopped by 79 | * pressing the e-stop button. 80 | */ 81 | if (!keep_camera_alive && (sms_done || continuous_done)) { 82 | 83 | bool ready_to_stop = true; 84 | 85 | // If this is a video move there might be a lead-out to wait for, so if the run time is less than the total calculated time, don't stop the program yet 86 | // totalProgramTime() and last_run_time are unsigned, so they must be recast as signed values to avoid rolling the result if last_runt_time is longer 87 | if (Motors::planType() != SMS && ((long)totalProgramTime() - (long)last_run_time) > 0) { 88 | 89 | ready_to_stop = false; 90 | 91 | // Debug output 92 | debug.functln(CYCLE_CAMERA + "All mot done moving"); 93 | if ((totalProgramTime() - last_run_time) > 0) { 94 | debug.funct(totalProgramTime()); 95 | debug.funct(last_run_time); 96 | debug.funct(CYCLE_CAMERA + "There are "); 97 | debug.funct((long)totalProgramTime() - (long)last_run_time); 98 | debug.functln("ms of lead-out remaining"); 99 | } 100 | } 101 | 102 | // stop program running w/o clearing variables 103 | if (ready_to_stop) { 104 | 105 | // If not running a ping-pong move, activate the camera trigger to stop the video recording 106 | if (!pingPongMode() && Motors::planType() == CONT_VID) 107 | Camera.expose(); 108 | // If ping pong mode is active and this is a continuous video shot, reverse direction and start the program again 109 | if (pingPongMode()) { 110 | ping_pong_shots += camera_fired; 111 | ping_pong_time += run_time; 112 | stopProgram(); 113 | reverseStartStop(); 114 | ping_pong_flag = true; 115 | startProgram(); 116 | } 117 | // Otherwise, just stop the program 118 | else{ 119 | stopProgram(); 120 | program_complete = true; 121 | } 122 | } 123 | debug.functln(CYCLE_CAMERA + "Bailing from camera cycle at point 1"); 124 | return; 125 | } 126 | // If either the SMS or continuous move is complete and the camera is in "keep alive" mode 127 | // indicate that the camera is still shooting 128 | else if (keep_camera_alive && (sms_done || continuous_done)) { 129 | still_shooting_flag = true; 130 | } 131 | 132 | // if in external interval mode, don't do anything if a force shot isn't registered 133 | if (altExtInt && !altForceShot) { 134 | debug.functln(CYCLE_CAMERA + "Skipping shot, waiting for external trigger"); 135 | return; 136 | } 137 | 138 | // trigger any outputs that need to go before the exposure 139 | if( (ALT_OUT_BEFORE == altInputs[0] || ALT_OUT_BEFORE == altInputs[1]) && cycleShotOK(true) ) { 140 | altBlock = ALT_OUT_BEFORE; 141 | altOutStart(ALT_OUT_BEFORE); 142 | debug.functln(CYCLE_CAMERA + "Bailing from camera cycle at point 2"); 143 | return; 144 | } 145 | 146 | 147 | // if enough time has passed, and we're ok to take an exposure 148 | // note: for slaves, we only get here by a master signal, so we don't check interval timing 149 | 150 | if( ComMgr.master() == false || ( millis() - camera_tm ) >= Camera.intervalTime() || !Camera.enable || external_intervalometer ) { 151 | 152 | debug.functln(CYCLE_CAMERA + "Shots: "); 153 | debug.funct(camera_fired); 154 | debug.funct(" "); 155 | for (byte i = 0; i < MOTOR_COUNT; i++){ 156 | debug.funct("Motor "); 157 | debug.funct(i); 158 | debug.funct(": "); 159 | debug.funct(motor[i].currentPos()); 160 | debug.funct(" "); 161 | } 162 | debug.functln(""); 163 | 164 | // skip camera actions if camera disabled 165 | if( ! Camera.enable ) { 166 | Engine.state(ST_MOVE); 167 | camera_tm = millis(); 168 | 169 | debug.functln(CYCLE_CAMERA + "Bailing from camera cycle at point 3"); 170 | return; 171 | } 172 | 173 | // trigger focus, if needed, which will set off the chain of 174 | // callback executions that will walk us through the complete exposure cycle. 175 | // -- if no focus is configured, nothing will happen but trigger 176 | // the callback that will trigger exposing the camera immediately 177 | debug.functln(CYCLE_CAMERA + "Camera busy: "); 178 | debug.functln(Camera.busy()); 179 | 180 | if( ! Camera.busy() ) { 181 | debug.functln(CYCLE_CAMERA + "Starting exposure cycle"); 182 | // only execute cycle if the camera is not currently busy 183 | Engine.state(ST_BLOCK); 184 | altBlock = ALT_OFF; 185 | altForceShot = false; 186 | camera_tm = millis(); 187 | Camera.focus(); 188 | } 189 | 190 | } 191 | 192 | } 193 | 194 | /** OK To Start a Shot Sequence? 195 | 196 | Checks whether or not a shot sequence (or pre-shot alt out trigger) is ok to execute. 197 | 198 | @param p_prealt 199 | Whether to check for a pre-shot alt out trigger (true) or normal shot sequence (false) 200 | 201 | @return 202 | True if good to go, false otherwise 203 | 204 | @author 205 | C. A. Church 206 | */ 207 | 208 | uint8_t cycleShotOK(uint8_t p_prealt) { 209 | 210 | const String CYCLE_SHOT_OK = "cycleShotOK() - "; 211 | 212 | debug.functln(CYCLE_SHOT_OK + "Enter function"); 213 | 214 | // if we're in alt i/o as external intervalometer mode... 215 | if( altExtInt ) { 216 | debug.functln(CYCLE_SHOT_OK + "Ext. interval mode active"); 217 | // don't do a pre-output clearance if alt_block is true... 218 | if( p_prealt && altBlock ) 219 | return false; 220 | 221 | // determine whether or not to fire based on alt_force_shot 222 | if (altForceShot == true) { 223 | debug.functln(CYCLE_SHOT_OK + "altForceShot detected ************"); 224 | return true; 225 | } 226 | else { 227 | debug.functln(CYCLE_SHOT_OK + "altForceShot not detected"); 228 | return false; 229 | } 230 | } 231 | 232 | // pre--output clearance check 233 | if(altBeforeDelay >= Camera.intervalTime() && !altBlock){ //Camera.intervalTime() is less than the altBeforeDelay, go as fast as possible 234 | return true; 235 | } 236 | else if( (millis() - camera_tm) >= (Camera.intervalTime() - altBeforeDelay) && ! altBlock ) 237 | return true; 238 | 239 | 240 | return false; 241 | 242 | } 243 | 244 | 245 | /** Move Motors Callback Handler 246 | 247 | Executes any required move 248 | 249 | @author 250 | C. A. Church 251 | */ 252 | 253 | void cycleClearToMove() { 254 | 255 | // signal any slaves that they're ok to proceed, if master 256 | ComMgr.masterSignal(); 257 | 258 | int minPlanLead = 0; 259 | 260 | // do not move if a motor delay is programmed... 261 | for(int i = 0; i < MOTOR_COUNT; i++){ 262 | 263 | if( (motor[i].enable())){ 264 | if ((minPlanLead != 0 && motor[i].planLeadIn() < minPlanLead) || (i == 0)) 265 | minPlanLead = motor[i].planLeadIn(); 266 | } 267 | 268 | } 269 | 270 | //do not move until the minimum plan lead in has passed, if planType() == CONT_VID then the plan lead in is in ms 271 | if ((minPlanLead > 0 && ((camera_fired <= minPlanLead && Motors::planType() != CONT_VID) || (Motors::planType() == CONT_VID && run_time <= minPlanLead)))) { 272 | Engine.state(ST_CLEAR); 273 | return; 274 | } 275 | 276 | // ok to run motors, if needed 277 | move_motor(); 278 | } 279 | 280 | 281 | /** Check Motor Status Callback Handler 282 | 283 | This callback handler handles the ST_RUN state. 284 | 285 | If continuous motion is requested, sets back to clear to fire state, no matter if motors 286 | are running. 287 | 288 | If interleaved (SMS) motion is requested, blocks fire state until all movement is complete. 289 | 290 | @author 291 | C. A. Church 292 | */ 293 | 294 | 295 | void cycleCheckMotor() { 296 | // still running 297 | 298 | // do not block on continuous motion of any sort 299 | if (OMMotorFunctions::planType() == SMS){ 300 | for (int i = 0; i < MOTOR_COUNT; i++){ 301 | if (motor[i].running() == true) 302 | return; 303 | } 304 | } 305 | 306 | // no longer running, ok to fire camera 307 | 308 | 309 | if( ComMgr.master() == true ) { 310 | // we are a timing master 311 | Engine.state(ST_CLEAR); 312 | 313 | // if autopause is enabled then pause upon completion of movement 314 | if( motor[0].autoPause == true || motor[1].autoPause == true || motor[2].autoPause == true ) { 315 | debug.functln("Auto pausing!!!"); 316 | pauseProgram(); 317 | } 318 | } 319 | else { 320 | // we are a slave - block until next slaveClear signal 321 | Engine.state(ST_BLOCK); 322 | } 323 | } 324 | 325 | 326 | /** Check Alt Output Post Trigger 327 | 328 | This callback handler handle the ST_ALTP state. 329 | 330 | If one or more I/Os are configured as post-exposure outputs, this state 331 | will cause a (non-blocking) run delay for the specified output delay time, and then 332 | trigger the outputs to fire. 333 | 334 | @author 335 | C. A. Church 336 | */ 337 | 338 | void cycleCheckAltPost() { 339 | 340 | static unsigned long alt_tm = millis(); 341 | 342 | // no output after set, move on to move... 343 | if( ! (ALT_OUT_AFTER == altInputs[0] || ALT_OUT_AFTER == altInputs[1])) 344 | { 345 | Engine.state(ST_MOVE); 346 | } else if( ! altBlock ) { //output after is set but hasn't been initiated yet 347 | altBlock = ALT_OUT_AFTER; 348 | alt_tm = millis(); 349 | } 350 | else if( ( millis() - alt_tm ) > altAfterDelay ) { //output after is set and enough time has pass to initiate it 351 | altBlock = ALT_OFF; 352 | altOutStart(ALT_OUT_AFTER); 353 | } 354 | 355 | } 356 | 357 | // Returns the total time of the current pass, plus all previous ping-pong passes 358 | unsigned long getRunTime(){ 359 | return last_run_time + ping_pong_time; 360 | } 361 | 362 | 363 | 364 | 365 | -------------------------------------------------------------------------------- /Firmware/Motion_Engine/OM_Debug.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | Motion Engine 5 | 6 | See dynamicperception.com for more information 7 | 8 | 9 | (c) 2008-2012 C.A. Church / Dynamic Perception LLC 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program. If not, see . 23 | 24 | 25 | */ 26 | /* 27 | 28 | ======================================== 29 | Debug functions 30 | ======================================== 31 | 32 | */ 33 | 34 | /* 35 | byte setDebugOutput(byte p_setting) 36 | 37 | Sets the USB debug output flags. This allows for turning on and off of specific debug message types. 38 | 39 | @param 40 | p_setting is an 8-bit number where each bit is a debug flag. A bit will toggle the corresponding bit 41 | in the usb_debug variable to its opposite state. Set only one bit at a time to avoid conflicting on/off requests. 42 | 43 | */ 44 | 45 | byte setDebugOutput(byte p_setting) { 46 | byte setting = debug.getState(); 47 | // If the specified flag is already on, turn it off, otherwise turn it on. 48 | if (setting & p_setting) 49 | setting &= ~p_setting; 50 | else 51 | setting |= p_setting; 52 | debug.setState(setting); 53 | 54 | // Set debug states for libraries 55 | bool motor_debug = false; 56 | bool camera_debug = false; 57 | if (setting & DebugClass::DB_FUNCT) 58 | camera_debug = true; 59 | if (setting & DebugClass::DB_MOTOR) 60 | motor_debug = true; 61 | OMCamera::debugOutput(camera_debug); 62 | OMMotorFunctions::debugOutput(motor_debug); 63 | 64 | // Return the full USB debug flag byte 65 | return setting; 66 | } 67 | 68 | /* 69 | void debugOn() / void debugOff() 70 | 71 | Sets the debug LED on or off, respectively 72 | 73 | */ 74 | 75 | void debugOn() { 76 | digitalWrite(DEBUG_PIN, HIGH); 77 | debug_LED = true; 78 | } 79 | 80 | void debugOff() { 81 | digitalWrite(DEBUG_PIN, LOW); 82 | debug_LED = false; 83 | } 84 | 85 | // Toggles the state of the debug LED 86 | void debugToggle(){ 87 | if(debug_LED) 88 | debugOff(); 89 | else 90 | debugOn(); 91 | } 92 | 93 | void selfDiagnostic() { 94 | // Check camera trigger 95 | for (byte i = 0; i < 2; i++) { 96 | Camera.expose(); 97 | delay(1000); 98 | } 99 | 100 | // Enable and sleep all the motors so all LEDs are off 101 | for (byte i = 0; i < MOTOR_COUNT; i++){ 102 | motor[i].enable(true); 103 | motor[i].sleep(true); 104 | } 105 | 106 | // Check the motor attachment 107 | uint8_t motor_attach = checkMotorAttach(); 108 | delay(250); 109 | 110 | // Report via enable lights which motors were detected 111 | for (byte i = 0; i < MOTOR_COUNT; i++){ 112 | // If a motor is detected, turn on the LED by turning off sleep mode 113 | if ((motor_attach >> i) & 1){ 114 | motor[i].sleep(false); 115 | delay(250); 116 | motor[i].sleep(true); 117 | delay(250); 118 | } 119 | else 120 | delay(1000); 121 | } 122 | 123 | // Turn sleep mode back off for all motor channels 124 | for (byte i = 0; i < MOTOR_COUNT; i++) 125 | motor[i].sleep(false); 126 | 127 | // Move motors forward 128 | unsigned long _time = millis(); 129 | int _speed = 4000; 130 | int _seconds = 3; 131 | for (byte i = 0; i < MOTOR_COUNT; i++){ 132 | motor[i].contSpeed(_speed); 133 | motor[i].continuous(false); 134 | motor[i].move(0, (_speed * _seconds)); // Determine the distanced based upon the speed and desired seconds above. 135 | } 136 | startISR(); 137 | while (motor[0].running() || motor[1].running() || motor[2].running()){ 138 | // Do nothing until all motors have stopped 139 | } 140 | for (byte i = 0; i < MOTOR_COUNT; i++) 141 | motor[i].move(1, (_speed * _seconds)); 142 | startISR(); 143 | } 144 | 145 | 146 | -------------------------------------------------------------------------------- /Firmware/Motion_Engine/OM_DevAddr.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | Motion Engine 5 | 6 | See dynamicperception.com for more information 7 | 8 | 9 | (c) 2008-2012 C.A. Church / Dynamic Perception LLC 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program. If not, see . 23 | 24 | 25 | */ 26 | 27 | 28 | 29 | /* 30 | 31 | ======================================== 32 | Device Addressing functions 33 | ======================================== 34 | 35 | */ 36 | 37 | 38 | 39 | void changeNodeAddr(byte addr) { 40 | // handle change device address 41 | // command 42 | device_address = addr; 43 | OMEEPROM::write(EE_ADDR, device_address); 44 | } 45 | 46 | -------------------------------------------------------------------------------- /Firmware/Motion_Engine/OM_EEPROM.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | Motion Engine 5 | 6 | See dynamicperception.com for more information 7 | 8 | 9 | (c) 2008-2012 C.A. Church / Dynamic Perception LLC 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program. If not, see . 23 | 24 | 25 | */ 26 | 27 | 28 | 29 | /* 30 | 31 | ======================================== 32 | EEPROM write/read functions 33 | ======================================== 34 | 35 | */ 36 | 37 | 38 | 39 | 40 | // EEPROM Memory Layout Version, change this any time you modify what is stored 41 | const unsigned int MEMORY_VERSION = 4; 42 | 43 | 44 | 45 | /** Check EEPROM Status 46 | 47 | If EEPROM hasn't been stored, or EEPROM version does not 48 | match our version, it saves our variables to eeprom memory. 49 | 50 | Otherwise, it reads stored variables from EEPROM memory 51 | 52 | @author C. A. Church 53 | */ 54 | 55 | void eepromCheck() { 56 | 57 | using namespace OMEEPROM; 58 | 59 | if( saved() ) { 60 | if( version() != MEMORY_VERSION ) 61 | eepromWrite(); 62 | else 63 | eepromRestore(); 64 | } 65 | else { 66 | eepromWrite(); 67 | } 68 | 69 | } 70 | 71 | /** Write All Variables to EEPROM */ 72 | 73 | void eepromWrite() { 74 | using namespace OMEEPROM; 75 | 76 | version(MEMORY_VERSION); 77 | 78 | write(EE_ADDR, device_address); 79 | write(EE_NAME, *device_name, 10); 80 | 81 | byte tempMS = 0; 82 | bool tempSleep = false; 83 | long tempPos = 0; 84 | long tempStart = 0; 85 | long tempStop = 0; 86 | long tempEnd = 0; 87 | 88 | for (int i = 0; i < MOTOR_COUNT; i++){ 89 | tempMS = motor[i].ms(); 90 | tempSleep = motor[i].sleep(); 91 | tempPos = motor[i].currentPos(); 92 | tempStart = motor[i].startPos(); 93 | tempStop = motor[i].stopPos(); 94 | tempEnd = endPos[i]; 95 | 96 | write(EE_MS_0 + EE_MOTOR_MEMORY_SPACE * i, tempMS); 97 | write(EE_SLEEP_0 + EE_MOTOR_MEMORY_SPACE * i, tempSleep); 98 | write(EE_POS_0 + EE_MOTOR_MEMORY_SPACE * i, tempPos); 99 | write(EE_START_0 + EE_MOTOR_MEMORY_SPACE * i, tempStart); 100 | write(EE_STOP_0 + EE_MOTOR_MEMORY_SPACE * i, tempStop); 101 | write(EE_END_0 + EE_MOTOR_MEMORY_SPACE * i, tempEnd); 102 | } 103 | } 104 | 105 | 106 | /** Read all variables from EEPROM */ 107 | 108 | void eepromRestore() { 109 | using namespace OMEEPROM; 110 | 111 | read(EE_ADDR, device_address); 112 | read(EE_NAME, *device_name, 10); 113 | read(EE_LOAD_POS, ee_load_curPos); 114 | read(EE_LOAD_START_STOP, ee_load_startStop); 115 | read(EE_LOAD_END, ee_load_endPos); 116 | 117 | // Make sure garbage isn't saved to these vars if they haven't been saved to 118 | // EEPROM before (e.g after initial loading of the firmware) 119 | if (ee_load_curPos != 0 && ee_load_curPos != 1) 120 | ee_load_curPos = 0; 121 | if (ee_load_startStop != 0 && ee_load_startStop != 1) 122 | ee_load_startStop = 0; 123 | if (ee_load_endPos != 0 && ee_load_endPos != 1) 124 | ee_load_endPos = 0; 125 | 126 | // There had been problems with reading the EEPROM values inside the motor setting functions, 127 | // so as a work around, they are saved into these temporary variables which are then used to load 128 | // the proper motor settings. 129 | 130 | byte tempMS = 0; 131 | bool tempSleep = false; 132 | long tempPos = 0; 133 | long tempStart = 0; 134 | long tempStop = 0; 135 | long tempEnd = 0; 136 | 137 | 138 | for (int i = 0; i < MOTOR_COUNT; i++){ 139 | 140 | read(EE_MS_0 + EE_MOTOR_MEMORY_SPACE * i, tempMS); 141 | read(EE_SLEEP_0 + EE_MOTOR_MEMORY_SPACE * i, tempSleep); 142 | read(EE_POS_0 + EE_MOTOR_MEMORY_SPACE * i, tempPos); 143 | read(EE_START_0 + EE_MOTOR_MEMORY_SPACE * i, tempStart); 144 | read(EE_STOP_0 + EE_MOTOR_MEMORY_SPACE * i, tempStop); 145 | read(EE_END_0 + EE_MOTOR_MEMORY_SPACE * i, tempEnd); 146 | 147 | motor[i].ms(tempMS); 148 | motor[i].sleep(tempSleep); 149 | if (ee_load_curPos) 150 | motor[i].currentPos(tempPos); 151 | if (ee_load_startStop){ 152 | motor[i].startPos(tempStart); 153 | motor[i].stopPos(tempStop); 154 | } 155 | if (ee_load_endPos){ 156 | endPos[i] = tempEnd; 157 | } 158 | } 159 | } 160 | 161 | 162 | -------------------------------------------------------------------------------- /Firmware/Motion_Engine/OM_KeyFrameControl.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | Motion Engine 5 | 6 | See dynamicperception.com for more information 7 | 8 | 9 | (c) 2008-2012 C.A. Church / Dynamic Perception LLC 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program. If not, see . 23 | 24 | 25 | */ 26 | 27 | boolean kf_okForSmsMove; 28 | int kf_curSmsFrame; 29 | boolean kf_auxFired = false; 30 | boolean kf_auxDone = false; 31 | boolean kf_focusFired = false; 32 | boolean kf_focusDone = false; 33 | boolean kf_shutterFired = false; 34 | boolean kf_shutterDone = false; 35 | boolean kf_forceShotInProgress = false; 36 | 37 | void kf_printKeyFrameData(){ 38 | 39 | // General program parameters 40 | USBSerial.print("~~~~~~ General Program Params ~~~~~~"); 41 | USBSerial.println(""); 42 | 43 | USBSerial.print("Max camera time: "); 44 | USBSerial.println(kf_getMaxCamTime()); 45 | USBSerial.print("Max move time: "); 46 | USBSerial.println(kf_getMaxMoveTime()); 47 | USBSerial.print("Run status: "); 48 | USBSerial.println(kf_getRunState()); 49 | 50 | if (kf_getRunState != 0){ 51 | USBSerial.print("Current run time: "); 52 | USBSerial.println(kf_getRunTime()); 53 | USBSerial.print("Percent complete: "); 54 | USBSerial.println(kf_getPercentDone()); 55 | } 56 | USBSerial.print("Program mode: "); 57 | USBSerial.println(Motors::planType()); 58 | USBSerial.print("Cont. video time: "); 59 | USBSerial.println(KeyFrames::getContVidTime()); 60 | 61 | for (byte i = 0; i < KeyFrames::getAxisCount(); i++){ 62 | // Indicate the current axis 63 | USBSerial.print("~~~~~~ AXIS "); 64 | USBSerial.print(i); 65 | USBSerial.println(" ~~~~~~"); 66 | USBSerial.println(""); 67 | 68 | // Print abscissas 69 | USBSerial.println("*** Abscissas ***"); 70 | for (byte j = 0; j < kf[i].getKFCount(); j++){ 71 | USBSerial.println(kf[i].getXN(j)); 72 | } 73 | USBSerial.println(""); 74 | 75 | // Print Positions 76 | USBSerial.println("*** Positions ***"); 77 | for (byte j = 0; j < kf[i].getKFCount(); j++){ 78 | USBSerial.println(kf[i].getFN(j)); 79 | } 80 | USBSerial.println(""); 81 | 82 | // Print velocities 83 | USBSerial.println("*** Velocities ***"); 84 | for (byte j = 0; j < kf[i].getKFCount(); j++){ 85 | USBSerial.println(kf[i].getDN(j)); 86 | } 87 | USBSerial.println(""); 88 | USBSerial.println(""); 89 | } 90 | 91 | } 92 | 93 | void kf_startProgram(){ 94 | kf_startProgram(false); 95 | } 96 | 97 | void kf_startProgram(boolean isBouncePass){ 98 | 99 | // If resuming 100 | if (kf_paused){ 101 | // Add the time of the last pause to the total pause time counter 102 | kf_pause_time += kf_this_pause; 103 | } 104 | // If starting a new program 105 | else{ 106 | debug.funct("Starting new type "); 107 | debug.funct((int)Motors::planType()); 108 | debug.functln(" KF program"); 109 | 110 | // Reset completion flag 111 | program_complete = false; 112 | 113 | // Reset the SMS vars 114 | kf_okForSmsMove = false; 115 | kf_curSmsFrame = 0; 116 | 117 | // Reset the total pause time counter 118 | kf_pause_time = 0; 119 | 120 | // Make sure the pause flag is off 121 | kf_paused = false; 122 | 123 | // Reset the camera vars 124 | kf_last_shot_tm = 0; 125 | kf_auxFired = false; 126 | kf_auxDone = false; 127 | kf_focusFired = false; 128 | kf_focusDone = false; 129 | kf_shutterFired = false; 130 | kf_shutterDone = false; 131 | kf_forceShotInProgress = false; 132 | camera_fired = 0; 133 | 134 | // Reset ping pong vals, if necessary 135 | if (!isBouncePass){ 136 | ping_pong_shots = 0; 137 | ping_pong_time = 0; 138 | } 139 | 140 | // Prep the movement and camera times 141 | kf_getMaxMoveTime(); 142 | kf_getMaxCamTime(); 143 | if (!isBouncePass) 144 | clearShotCounter(); 145 | 146 | // SMS Moves 147 | if (Motors::planType() == SMS){ 148 | // Convert from "frames" to real milliseconds, based upon the camera interval 149 | Camera.intervalTime(); 150 | kf_getMaxMoveTime(); 151 | kf_getMaxCamTime(); 152 | // Make sure joystick mode is off, then set move speed for the motors 153 | joystickSet(false); 154 | } 155 | // Cont TL and Vid moves 156 | else{ 157 | // Turn on joystick mode 158 | joystickSet(true); 159 | 160 | // Set the initial motor speeds 161 | for (byte i = 0; i < MOTOR_COUNT; i++){ 162 | // Don't touch motors that don't have any key frames 163 | if (kf[i].getKFCount() > 0){ 164 | // If the first key frame isn't at x == 0 (i.e. there is a lead-in), set velocity to 0 165 | if (kf[i].getXN(0) == 0){ 166 | setJoystickSpeed(i, kf[i].vel(0) * MILLIS_PER_SECOND); 167 | } 168 | else{ 169 | setJoystickSpeed(i, 0); 170 | } 171 | } 172 | } 173 | } 174 | 175 | // Initialize the run timers 176 | kf_run_time = 0; 177 | kf_start_time = millis(); 178 | kf_last_update = millis(); 179 | } 180 | 181 | // Turn on the key frame program flag and turn the paused flag off 182 | kf_running = true; 183 | kf_paused = false; 184 | kf_just_started = true; 185 | } 186 | 187 | void kf_pauseProgram(){ 188 | 189 | debug.funct("PAUSING KF PROGRAM"); 190 | 191 | // Stop all motors 192 | for (byte i = 0; i < MOTOR_COUNT; i++){ 193 | debug.funct("Stopping motor "); 194 | debug.functln(i); 195 | setJoystickSpeed(i, 0); 196 | } 197 | 198 | // Set the pause flag 199 | kf_paused = true; 200 | 201 | // Reset the current pause duration counter 202 | kf_this_pause = 0; 203 | 204 | // Log the start time of the pause 205 | kf_pause_start = millis(); 206 | } 207 | 208 | void kf_stopProgram(){ 209 | kf_stopProgram(false); 210 | } 211 | 212 | void kf_stopProgram(boolean savePingPongVals){ 213 | 214 | debug.funct("STOPPING KF PROGRAM"); 215 | 216 | // Make sure all motors are stopped 217 | for (byte i = 0; i < MOTOR_COUNT; i++){ 218 | setJoystickSpeed(i, 0); 219 | } 220 | 221 | // Disable joystick mode 222 | joystickSet(false); 223 | 224 | // Turn off the key frame program flag 225 | kf_running = false; 226 | kf_paused = false; 227 | still_shooting_flag = false; 228 | 229 | if (!savePingPongVals){ 230 | ping_pong_flag = false; 231 | kf_ping_pong_time = 0; 232 | ping_pong_shots = 0; 233 | } 234 | 235 | // If it's a video move, trigger the camera once to stop the recording 236 | if (Motors::planType() == CONT_VID) 237 | Camera.expose(); 238 | } 239 | 240 | void kf_updateProgram(){ 241 | unsigned long cur_time = millis(); 242 | static unsigned long last_blink; 243 | const int BLINK_DELAY = 500; 244 | if (kf_run_time == 0){ 245 | last_blink = cur_time; 246 | } 247 | 248 | // If the program is paused, just keep track of the pause time 249 | if (kf_paused){ 250 | kf_this_pause = millis() - kf_pause_start; 251 | debug.funct("Pause length: "); 252 | debug.functln(kf_this_pause); 253 | return; 254 | } 255 | 256 | // Update run_time, don't include time spent paused 257 | kf_run_time = millis() - kf_start_time - kf_pause_time; 258 | 259 | //debug.funct("Run time: "); 260 | //debug.functln(kf_run_time); 261 | 262 | // Adding a small delay seems to keep the controller from randomly locking. I don't know why... 263 | int time_delay = 500; 264 | unsigned long start_wait = micros(); 265 | while (micros() - start_wait < time_delay){ 266 | // Wait for the delay to finish 267 | } 268 | 269 | // Don't do anything else until the start delay is done (but skip if on a ping-pong pass) 270 | if (kf_run_time < start_delay && !ping_pong_flag){ 271 | delay_flag = true; 272 | if (cur_time - last_blink > BLINK_DELAY){ 273 | debugToggle(); 274 | last_blink = cur_time; 275 | } 276 | return; 277 | } 278 | 279 | // Set proper post-delay debug LED status 280 | if (external_intervalometer) 281 | debugOn(); 282 | else 283 | debugOff(); 284 | 285 | delay_flag = false; 286 | 287 | 288 | // If this is the beginning of the program, just after the start delay... 289 | if (kf_just_started){ 290 | // ...trigger the camera once to start the recording if it's a video move. 291 | if (Motors::planType() == CONT_VID) 292 | Camera.expose(); 293 | kf_just_started = false; 294 | } 295 | 296 | 297 | // Continuous move update (don't update in keep-alive phase) 298 | if (Motors::planType() != SMS && !still_shooting_flag){ 299 | kf_updateContSpeed(); 300 | } 301 | 302 | // Check whether the camera needs to fire (but not for video mode) 303 | if (Motors::planType() != CONT_VID) 304 | kf_CameraCheck(); 305 | 306 | // SMS move update (don't update in keep-alive phase) 307 | if (Motors::planType() == SMS && !still_shooting_flag){ 308 | kf_updateSMS(); 309 | } 310 | 311 | // Check to see if the program is done 312 | long totalTime = kf_getMaxCamTime(); 313 | // Only wait for the start delay on the first pass 314 | if (!ping_pong_flag) 315 | totalTime += start_delay; 316 | if (kf_run_time > totalTime){ 317 | // Make sure the motors are stopped, but let the program continue running 318 | if (keep_camera_alive){ 319 | debug.serln("Starting keep alive phase"); 320 | still_shooting_flag = true; 321 | 322 | // Make sure all motors are stopped 323 | for (byte i = 0; i < MOTOR_COUNT; i++){ 324 | setJoystickSpeed(i, 0); 325 | } 326 | 327 | // Disable joystick mode 328 | joystickSet(false); 329 | } 330 | else{ 331 | debug.serln("Stopping kf program"); 332 | // If ping-pong mode is active, reverse and start a new program 333 | if (pingPongMode()){ 334 | // The shot count and run time are reset when starting a new program, 335 | // so add the shots and them to separate counters for serial reporting 336 | // and indicate to the stop function that they should not be reset 337 | kf_ping_pong_time += kf_run_time; 338 | ping_pong_shots += camera_fired; 339 | kf_stopProgram(true); 340 | debug.serln("Starting ping-pong phase"); 341 | ping_pong_flag = true; 342 | debug.serln("Reversing key points"); 343 | reverseStartStop(); 344 | debug.serln("Starting new kf bounce program"); 345 | kf_startProgram(true); 346 | } 347 | else{ 348 | kf_stopProgram(); 349 | program_complete = true; 350 | } 351 | } 352 | } 353 | } 354 | 355 | void kf_updateContSpeed(){ 356 | 357 | // If the update time has elapsed, update the motor speed 358 | if (millis() - kf_last_update > KeyFrames::updateRate()){ 359 | for (byte i = 0; i < MOTOR_COUNT; i++){ 360 | // Determine the maximum run time for this axis 361 | float thisAxisMaxTime = kf[i].getXN(kf[i].getKFCount() - 1); 362 | if (Motors::planType() == SMS) 363 | thisAxisMaxTime = thisAxisMaxTime * Camera.intervalTime(); 364 | 365 | // Set the approriate speed, but don't touch motors that don't have any key frames 366 | if (kf[i].getKFCount() > 0){ 367 | float speed; 368 | if (kf_run_time > thisAxisMaxTime + start_delay) 369 | speed = 0; 370 | else{ 371 | // If the time is before the first key frame or after the last, it's a lead-in/out and speed should be 0 372 | if (kf_run_time < kf[i].getXN(0) + start_delay || kf_run_time > kf[i].getXN(kf[i].getKFCount() - 1) + start_delay) 373 | speed = 0; 374 | else 375 | speed = kf[i].vel((float)kf_run_time - start_delay) * MILLIS_PER_SECOND; // Convert from steps/millisecond to steps/sec 376 | } 377 | setJoystickSpeed(i, speed); 378 | } 379 | } 380 | kf_last_update = millis(); 381 | } 382 | } 383 | 384 | void kf_updateSMS(){ 385 | 386 | // If we're not ready for a move (i.e. the camera is busy or we just finished one), don't do anything 387 | if (!kf_okForSmsMove || kf_run_time > kf_getMaxMoveTime() + start_delay){ 388 | return; 389 | } 390 | 391 | // Send the motors to their next locations 392 | debug.functln("Sending motors to new locations"); 393 | for (int i = 0; i < MOTOR_COUNT; i++){ 394 | 395 | // Make sure there is a point to actually query 396 | if (kf[i].getKFCount() < 2 || kf_curSmsFrame + 1 > kf[i].getXN(kf[i].getKFCount() - 1)) 397 | continue; 398 | 399 | float nextPos = kf[i].pos(kf_curSmsFrame + 1); 400 | 401 | debug.funct("About to send to location #: "); 402 | debug.functln(kf_curSmsFrame + 1); 403 | debug.funct("Sending to "); 404 | debug.functln(nextPos); 405 | debug.functln(""); 406 | 407 | sendTo(i, (long)nextPos); 408 | } 409 | kf_curSmsFrame++; 410 | kf_okForSmsMove = false; 411 | } 412 | 413 | void kf_CameraCheck() { 414 | 415 | const String KF_CAM_CHECK = "kf_CameraCheck() - "; 416 | 417 | int auxPreShotTime = 0; 418 | 419 | // If this is the last shot of a pass during ping-pong mode, skip it 420 | if (pingPongMode() && camera_fired == Camera.getMaxShots()){ 421 | return; 422 | } 423 | 424 | // If in external interval mode, don't do anything if a force shot isn't registered 425 | if (altExtInt && !altForceShot && !kf_forceShotInProgress) { 426 | debug.functln(KF_CAM_CHECK + "Skipping shot, waiting for external trigger"); 427 | return; 428 | } 429 | 430 | // If there's an aux event before the camera events, set the time needed for that 431 | if (ALT_OUT_BEFORE == altInputs[0] || ALT_OUT_BEFORE == altInputs[1]){ 432 | auxPreShotTime = altBeforeDelay; 433 | } 434 | 435 | boolean auxLongerThanInt = auxPreShotTime >= Camera.intervalTime(); 436 | boolean timeForNewShot = (kf_run_time - kf_last_shot_tm) >= (Camera.intervalTime() - auxPreShotTime); 437 | 438 | // If it's time, start a new shot 439 | if (((auxLongerThanInt || timeForNewShot) && !altBlock) || altForceShot){ //Camera.intervalTime() is less than the altBeforeDelay, go as fast as possible 440 | 441 | kf_last_shot_tm = kf_run_time; 442 | 443 | kf_auxFired = false; 444 | kf_auxDone = false; 445 | kf_focusFired = false; 446 | kf_focusDone = false; 447 | kf_shutterFired = false; 448 | kf_shutterDone = false; 449 | 450 | if (altForceShot){ 451 | kf_forceShotInProgress = true; 452 | altForceShot = false; 453 | } 454 | } 455 | 456 | // Trigger any outputs that need to go before the exposure 457 | if ((ALT_OUT_BEFORE == altInputs[0] || ALT_OUT_BEFORE == altInputs[1]) && cycleShotOK(true) && !kf_auxDone) { 458 | if (!kf_auxFired){ 459 | altBlock = ALT_OUT_BEFORE; 460 | altOutStart(ALT_OUT_BEFORE); 461 | debug.functln(KF_CAM_CHECK + "Bailing from camera cycle at point 2"); 462 | kf_auxFired = true; 463 | return; 464 | } 465 | 466 | // If not enough time for the aux function has elapsed, return 467 | if (kf_run_time < kf_last_shot_tm + auxPreShotTime){ 468 | return; 469 | } 470 | kf_auxDone = true; 471 | } 472 | 473 | altBlock = ALT_OFF; 474 | altForceShot = false; 475 | 476 | // Trigger the focus 477 | if (!kf_focusDone){ 478 | if (!kf_focusFired){ 479 | debug.funct("Time at focus: "); 480 | debug.functln(kf_run_time); 481 | Camera.focus(); 482 | kf_focusFired = true; 483 | return; 484 | } 485 | 486 | // If not enough time for the focus has elapsed, return 487 | if (kf_run_time < kf_last_shot_tm + auxPreShotTime + Camera.focusTime()){ 488 | return; 489 | } 490 | kf_focusDone = true; 491 | } 492 | 493 | // Trigger the exposure 494 | if (!kf_shutterDone){ 495 | if (!kf_shutterFired){ 496 | debug.funct("Time at exposure: "); 497 | debug.functln(kf_run_time); 498 | Camera.expose(); 499 | kf_shutterFired = true; 500 | } 501 | 502 | // If not enough time for the exposure has elapsed, return 503 | if (kf_run_time < kf_last_shot_tm + auxPreShotTime + Camera.focusTime() + Camera.triggerTime() + Camera.delayTime()){ 504 | return; 505 | } 506 | kf_shutterDone = true; 507 | kf_forceShotInProgress = false; 508 | 509 | // One the camera functions are complete, it's okay to make the next SMS move 510 | debug.functln("Shutter done, ready for move"); 511 | kf_okForSmsMove = true; 512 | } 513 | 514 | } 515 | 516 | void kf_auxCycleStart(byte p_mode) { 517 | 518 | //Pins for the I/O 519 | const byte AUX_RING = 24; //PD0 520 | const byte AUX_TIP = 25; //PD1 521 | 522 | uint8_t altStarted = false; 523 | 524 | unsigned int adelay = p_mode == ALT_OUT_BEFORE ? altBeforeMs : altAfterMs; 525 | 526 | for (byte i = 0; i < 2; i++) { 527 | if (p_mode == altInputs[i]) { 528 | 529 | // note that alt 3 is on a different register.. 530 | if (i == 0) 531 | digitalWrite(AUX_RING, altOutTrig); 532 | else 533 | digitalWrite(AUX_TIP, altOutTrig); 534 | 535 | altStarted = true; 536 | } 537 | } 538 | 539 | if (altStarted) { 540 | MsTimer2::set(adelay, altOutStop); 541 | MsTimer2::start(); 542 | Engine.state(ST_BLOCK); 543 | } 544 | else if (p_mode == ALT_OUT_BEFORE) { 545 | //clear to shoot 546 | Engine.state(ST_CLEAR); 547 | } 548 | else { 549 | // clear to move 550 | Engine.state(ST_MOVE); 551 | } 552 | 553 | } 554 | 555 | /* 556 | This function compares the max SMS speeds for each 557 | axis against the maximum possible speed for each axis. 558 | If at least one of them exceeds the axis' max speed, 559 | the function returns false. 560 | */ 561 | boolean kf_ValidateSMSProgram(){ 562 | for (byte i = 0; i < MOTOR_COUNT; i++){ 563 | float thisMaxSpeed = kf_MaxSMSSpeed(i); 564 | 565 | // Return false if one of the segments requires a speed higher than is possible 566 | if (thisMaxSpeed > motor[i].maxSpeed()){ 567 | return false; 568 | } 569 | } 570 | // If everything checks out, return true 571 | return true; 572 | } 573 | 574 | /* 575 | This function finds the maximum steps per second required 576 | for the requested axis' SMS key frame program. Only use if 577 | an SMS key frame program has already been set! 578 | */ 579 | float kf_MaxSMSSpeed(int axis){ 580 | 581 | float maxTime = kf[axis].getXN(kf[axis].getKFCount() - 1); 582 | int kfCount = kf[axis].getKFCount(); 583 | float timeInc = maxTime / kfCount; 584 | float maxSpeed = 0; 585 | 586 | // For each key frame for that axis 587 | for (byte i = 0; i < kfCount; i++){ 588 | 589 | // Find step difference for this segment 590 | float startTime = timeInc * i; 591 | float stopTime = timeInc * (i + 1); 592 | float startStep = kf[axis].pos(startTime); 593 | float stopStep = kf[axis].pos(stopTime); 594 | 595 | float stepsPerSec = (stopStep - startStep) / timeInc; 596 | 597 | if (stepsPerSec > maxSpeed) 598 | 599 | // Return false if one of the segments requires a speed higher than is possible 600 | if (stepsPerSec > maxSpeed){ 601 | maxSpeed = stepsPerSec; 602 | } 603 | } 604 | return maxSpeed; 605 | } 606 | 607 | long kf_getMaxMoveTime(){ 608 | 609 | long move_time = 0; 610 | 611 | // SMS and cont. TL mode 612 | if (Motors::planType() != CONT_VID){ 613 | move_time = Camera.getMaxShots() * Camera.intervalTime(); 614 | if (!kf_running) 615 | debug.funct("Getting TL move time: "); 616 | } 617 | // Continuous video mode 618 | else{ 619 | move_time = KeyFrames::getContVidTime(); 620 | if (!kf_running) 621 | debug.funct("Getting vid move time: "); 622 | } 623 | if (!kf_running){ 624 | debug.funct(move_time); 625 | debug.functln("ms"); 626 | } 627 | 628 | return move_time; 629 | } 630 | 631 | 632 | int kf_getRunState(){ 633 | 634 | const int STOPPED = 0; 635 | const int RUNNING = 1; 636 | const int PAUSED = 2; 637 | 638 | int ret; 639 | if (!kf_running){ 640 | ret = STOPPED; 641 | } 642 | else if (kf_running && !kf_paused){ 643 | ret = RUNNING; 644 | } 645 | // This is weird: if I don't explicitly compare the kf_paused value in the else if below, I get the 646 | // following build error: Motion_Engine.ino:12: error: expected unqualified-id before 'else' 647 | // Strange... 648 | else if (kf_running && kf_paused == true){ 649 | ret = PAUSED; 650 | } 651 | 652 | return ret; 653 | } 654 | 655 | 656 | long kf_getRunTime(){ 657 | return kf_run_time + kf_ping_pong_time; 658 | } 659 | 660 | 661 | long kf_getMaxProgramTime(){ 662 | if (Motors::planType() == CONT_VID) 663 | return kf_getMaxMoveTime() + start_delay; 664 | else 665 | return kf_getMaxCamTime() + start_delay; 666 | } 667 | 668 | 669 | long kf_getMaxCamTime(){ 670 | long ret = kf_getMaxMoveTime() + Camera.focusTime() + Camera.triggerTime(); 671 | return ret; 672 | } 673 | 674 | 675 | int kf_getPercentDone(){ 676 | int ret; 677 | 678 | if (Motors::planType() == CONT_VID) 679 | ret = ((float)kf_run_time / (kf_getMaxMoveTime() + start_delay)) * PERCENT_CONVERT; 680 | else 681 | ret = ((float)kf_run_time / (kf_getMaxCamTime() + start_delay)) * PERCENT_CONVERT; 682 | 683 | return ret; 684 | } 685 | -------------------------------------------------------------------------------- /Firmware/Motion_Engine/OM_LimitHandler.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | Motion Engine 5 | 6 | See dynamicperception.com for more information 7 | 8 | 9 | (c) 2008-2012 C.A. Church / Dynamic Perception LLC 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program. If not, see . 23 | 24 | 25 | */ 26 | 27 | 28 | // debounce threshold time 29 | const int ALT_TRIG_THRESH = 750; 30 | 31 | 32 | 33 | 34 | //Limit switch inputs (0 = detached, 1 = attached RISING, 2 = attached FALLING, 3 = attached CHANGE) 35 | byte ring = 0; 36 | byte tip = 0; 37 | 38 | //Pins for the I/O 39 | const byte AUX_RING = 24; //PD0 40 | const byte AUX_TIP = 25; //PD1 41 | 42 | 43 | 44 | //timer for the I/O interrupt 45 | unsigned long trigLast = millis(); 46 | 47 | 48 | 49 | void limitSwitchAttach(byte p_altDirection) { 50 | 51 | 52 | switch(p_altDirection){ 53 | case 0: 54 | altDirection = RISING; 55 | break; 56 | case 1: 57 | altDirection = FALLING; 58 | break; 59 | case 2: 60 | altDirection = CHANGE; 61 | break; 62 | default: 63 | break; 64 | } 65 | } 66 | 67 | 68 | /** Alt I/O Setup 69 | 70 | */ 71 | void altSetup() { 72 | altConnect(0 , altInputs[0]); 73 | altConnect(1, altInputs[1]); 74 | 75 | // check if any inputs are set to ext intervalometer 76 | uint8_t doExt = false; 77 | 78 | for( byte i = 0; i < 2; i++ ) 79 | if( altInputs[i] == ALT_EXTINT ) 80 | doExt = true; 81 | 82 | altExtInt = doExt; 83 | 84 | } 85 | 86 | /** Handler For Alt I/O Action Trigger 87 | 88 | Given a particular Alt I/O line being triggered in input mode, this function 89 | debounces and executes any required action for an Alt I/O line. 90 | 91 | @param p_which 92 | The I/O line that triggered, 0 or 1. 93 | 94 | @author 95 | C. A. Church 96 | */ 97 | 98 | void altHandler(byte p_which) { 99 | 100 | if((millis() - trigLast) >= ALT_TRIG_THRESH ) { 101 | 102 | trigLast = millis(); 103 | 104 | if( altInputs[p_which] == ALT_START) 105 | startProgram(); 106 | else if( altInputs[p_which] == ALT_STOP_MOTORS && running == true) 107 | stopAllMotors(); 108 | else if( altInputs[p_which] == ALT_STOP) 109 | stopProgram(); 110 | else if( altInputs[p_which] == ALT_TOGGLE) { 111 | if( running ) 112 | stopProgram(); 113 | else 114 | startProgram(); 115 | } 116 | else if( altInputs[p_which] == ALT_EXTINT ) { 117 | 118 | debug.serln("External trigger detected"); 119 | 120 | // set camera ok to fire 121 | altForceShot = true; 122 | // do not clear the state, as we may be in the middle of a move 123 | // when a trigger is received! (or some other activity, for that matter) 124 | // Engine.state(ST_CLEAR); 125 | } 126 | else if( altInputs[p_which] == ALT_DIR) { 127 | motor[0].dir( !motor[0].dir() ); 128 | motor[1].dir( !motor[1].dir() ); 129 | motor[2].dir( !motor[2].dir() ); 130 | } else if (altInputs[p_which] == ALT_SET_HOME){ 131 | stopAllMotors(); 132 | motor[0].homeSet(); 133 | motor[1].homeSet(); 134 | motor[2].homeSet(); 135 | } else if (altInputs[p_which] == ALT_SET_END){ 136 | stopAllMotors(); 137 | motor[0].maxSteps((motor[0].currentPos())); 138 | motor[1].maxSteps((motor[1].currentPos())); 139 | motor[2].maxSteps((motor[2].currentPos())); 140 | } 141 | 142 | } //end if millis... 143 | } 144 | 145 | /** Handler for ISR One */ 146 | void altISROne() { 147 | altHandler(0); 148 | } 149 | 150 | /** Handler for ISR Two */ 151 | void altISRTwo() { 152 | altHandler(1); 153 | } 154 | 155 | /** Connect (or Disconnect) an Alt I/O Line 156 | 157 | This function attches or detaches the required interrupt 158 | given an I/O line and a mode. 159 | 160 | @param p_which 161 | Which I/O, 0 or 1 162 | 163 | @param p_mode 164 | A valid altMode 165 | 166 | @author 167 | C. A. Church 168 | */ 169 | 170 | void altConnect(byte p_which, byte p_mode) { 171 | 172 | 173 | altInputs[p_which] = p_mode; 174 | //sets the pin affected 175 | byte pin = AUX_RING; 176 | if (p_which == 1) 177 | pin = AUX_TIP; 178 | 179 | if( p_which == 0) { 180 | detachInterrupt(2); 181 | } else if ( p_which == 1) { 182 | detachInterrupt(3); 183 | } 184 | 185 | // disable the input? 186 | 187 | if( p_mode == ALT_OFF ) { 188 | pinMode(pin, INPUT); 189 | return; 190 | } 191 | 192 | // only attach interrupts for input modes 193 | if( p_mode != ALT_OUT_BEFORE && p_mode != ALT_OUT_AFTER ) { 194 | // set pin as input 195 | pinMode(pin, INPUT); 196 | // enable pull-up resistor 197 | digitalWrite(pin, HIGH); 198 | 199 | // regarding 6 and 7 below - don't ask me.. ask who ever did that wierd order in WInterrupts.c 200 | switch( p_which ) { 201 | case 0: //sets interrupt attached to ring 202 | attachInterrupt(2, altISROne, altDirection); 203 | break; 204 | case 1: //sets interrupt attached to tip 205 | attachInterrupt(3, altISRTwo, altDirection); 206 | break; 207 | } 208 | } else { 209 | // it's an output mode 210 | pinMode(pin, OUTPUT); 211 | digitalWrite(pin, ! altOutTrig); 212 | } 213 | 214 | 215 | } 216 | 217 | 218 | /** Trigger Outputs 219 | 220 | Triggers all configured outputs for the given mode, for the given length 221 | of time. Blocks state engine while output is triggered, and registers callback 222 | to bring output down. 223 | 224 | @param p_mode 225 | Either ALT_TRIG_A or ALT_TRIG_B, specifying after or before types 226 | 227 | @author 228 | C. A. Church 229 | 230 | */ 231 | 232 | 233 | void altOutStart(byte p_mode) { 234 | 235 | uint8_t altStarted = false; 236 | 237 | unsigned int adelay = p_mode == ALT_OUT_BEFORE ? altBeforeMs : altAfterMs; 238 | 239 | for(byte i = 0; i < 2; i++) { 240 | if( p_mode == altInputs[i]) { 241 | 242 | // note that alt 3 is on a different register.. 243 | if( i == 0 ) 244 | digitalWrite(AUX_RING, altOutTrig); 245 | else 246 | digitalWrite(AUX_TIP, altOutTrig); 247 | 248 | altStarted = true; 249 | } 250 | } 251 | 252 | if( altStarted ) { 253 | MsTimer2::set(adelay, altOutStop); 254 | MsTimer2::start(); 255 | Engine.state(ST_BLOCK); 256 | } 257 | else if( p_mode == ALT_OUT_BEFORE ) { 258 | //clear to shoot 259 | Engine.state(ST_CLEAR); 260 | } 261 | else { 262 | // clear to move 263 | Engine.state(ST_MOVE); 264 | } 265 | 266 | } 267 | 268 | /** Bring Down any Triggered Outputs 269 | 270 | @author 271 | C. A. Church 272 | */ 273 | 274 | void altOutStop() { 275 | 276 | MsTimer2::stop(); 277 | 278 | 279 | for(byte i = 0; i < 2; i++) { 280 | if( ALT_OUT_BEFORE == altInputs[i] || ALT_OUT_AFTER == altInputs[i] ) { 281 | // note that alt 3 is on a different register.. 282 | if( i == 0 ) 283 | digitalWrite(AUX_RING, ! altOutTrig); 284 | else 285 | digitalWrite(AUX_TIP, ! altOutTrig); 286 | } 287 | } 288 | 289 | // set correct state to either clear to fire, or clear to move 290 | 291 | if( altBlock == ALT_OUT_BEFORE ) 292 | { 293 | Engine.state(ST_CLEAR); 294 | } 295 | else 296 | { 297 | Engine.state(ST_MOVE); 298 | } 299 | 300 | } 301 | 302 | -------------------------------------------------------------------------------- /Firmware/Motion_Engine/OM_MotorMaster.h: -------------------------------------------------------------------------------- 1 | #include 2 | // must load before wconstants to prevent issues 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | 9 | // DEFAULT PIN ASSIGNMENTS 10 | 11 | 12 | /* ================================ 13 | Motor 1 Pins 14 | ===============================*/ 15 | #ifndef OM_MOT1_DSTEP 16 | #define OM_MOT1_DSTEP 45 17 | #endif 18 | #ifndef OM_MOT1_DDIR 19 | #define OM_MOT1_DDIR 16 20 | #endif 21 | #ifndef OM_MOT1_DSLP 22 | #define OM_MOT1_DSLP 32 23 | #endif 24 | #ifndef OM_MOT1_DMS1 25 | #define OM_MOT1_DMS1 17 26 | #endif 27 | #ifndef OM_MOT1_DMS2 28 | #define OM_MOT1_DMS2 18 29 | #endif 30 | #ifndef OM_MOT1_DMS3 31 | #define OM_MOT1_DMS3 19 32 | #endif 33 | #ifndef OM_MOT1_STPREG 34 | #define OM_MOT1_STPREG PORTF 35 | #endif 36 | #ifndef OM_MOT1_STPFLAG 37 | #define OM_MOT1_STPFLAG PORTF5 38 | #endif 39 | 40 | /* ================================ 41 | Motor 2 Pins 42 | ===============================*/ 43 | #ifndef OM_MOT2_DSTEP 44 | #define OM_MOT2_DSTEP 46 45 | #endif 46 | #ifndef OM_MOT2_DDIR 47 | #define OM_MOT2_DDIR 21 48 | #endif 49 | #ifndef OM_MOT2_DSLP 50 | #define OM_MOT2_DSLP 20 51 | #endif 52 | #ifndef OM_MOT2_DMS1 53 | #define OM_MOT2_DMS1 29 54 | #endif 55 | #ifndef OM_MOT2_DMS2 56 | #define OM_MOT2_DMS2 30 57 | #endif 58 | #ifndef OM_MOT2_DMS3 59 | #define OM_MOT2_DMS3 31 60 | #endif 61 | #ifndef OM_MOT2_STPREG 62 | #define OM_MOT2_STPREG PORTF 63 | #endif 64 | #ifndef OM_MOT2_STPFLAG 65 | #define OM_MOT2_STPFLAG PORTF6 66 | #endif 67 | 68 | /* ================================ 69 | Motor 3 Pins 70 | ===============================*/ 71 | #ifndef OM_MOT3_DSTEP 72 | #define OM_MOT3_DSTEP 47 73 | #endif 74 | #ifndef OM_MOT3_DDIR 75 | #define OM_MOT3_DDIR 34 76 | #endif 77 | #ifndef OM_MOT3_DSLP 78 | #define OM_MOT3_DSLP 33 79 | #endif 80 | #ifndef OM_MOT3_DMS1 81 | #define OM_MOT3_DMS1 15 82 | #endif 83 | #ifndef OM_MOT3_DMS2 84 | #define OM_MOT3_DMS2 43 85 | #endif 86 | #ifndef OM_MOT3_DMS3 87 | #define OM_MOT3_DMS3 44 88 | #endif 89 | #ifndef OM_MOT3_STPREG 90 | #define OM_MOT3_STPREG PORTF 91 | #endif 92 | #ifndef OM_MOT3_STPFLAG 93 | #define OM_MOT3_STPFLAG PORTF7 94 | #endif 95 | 96 | 97 | #define OM_MOT_SSTATE HIGH 98 | #define OM_MOT_SAFE 10 99 | 100 | #define OM_MOT_DONE 1 101 | #define OM_MOT_MOVING 2 102 | #define OM_MOT_BEGIN 3 103 | 104 | #define OM_MOT_LINEAR 4 105 | #define OM_MOT_QUAD 5 106 | #define OM_MOT_QUADINV 6 107 | -------------------------------------------------------------------------------- /Firmware/Motion_Engine/OM_MotorMaster.ino: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | Motor Control Library 5 | 6 | OpenMoco nanoMoCo Core Engine Libraries 7 | 8 | See www.openmoco.org for more information 9 | 10 | (c) 2008-2011 C.A. Church / Dynamic Perception LLC 11 | 12 | This program is free software: you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation, either version 3 of the License, or 15 | (at your option) any later version. 16 | 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this program. If not, see . 24 | 25 | 26 | */ 27 | 28 | #include 29 | //#include 30 | 31 | void(*f_motSignal)(uint8_t) = 0; 32 | 33 | 34 | 35 | 36 | 37 | /** Set Callback Handler for motor master 38 | 39 | As actions start and complete, a callback is used to signal what is happening, 40 | without having to query the method to see if a given action is still occuring. 41 | 42 | By passing a function pointer to this method, that function will be executed 43 | at each one of these moments, and passed a single, one byte argument that 44 | matches the signal which is to be sent. The template for this function is: 45 | 46 | @code 47 | void function(byte val) { } 48 | @endcode 49 | 50 | The following codes are defined: 51 | 52 | @code 53 | OM_MOT_DONE 54 | - The motor has stopped moving 55 | OM_MOT_MOVING 56 | - The motor has begun moving 57 | @endcode 58 | 59 | An example of an appropriate callback handler: 60 | 61 | @code 62 | #include "TimerOne.h" 63 | #include "OMMotorMaster.h" 64 | 65 | OMMotorMaster Motor = OMMotorMaster(); 66 | 67 | void setup() { 68 | 69 | Motor.enable(true); 70 | Motor.continuous(false); 71 | Motor.setHandler(motorCallback); 72 | 73 | Serial.begin(19200); 74 | 75 | } 76 | 77 | void loop() { 78 | 79 | if( ! Motor.running() ) { 80 | delay(1000); 81 | Serial.println("Moving!"); 82 | Motor.move(true, 1000); 83 | } 84 | 85 | } 86 | 87 | void motorCallback( byte code ) { 88 | 89 | if( code == OM_MOT_DONE ) { 90 | Serial.println("Got Done!"); 91 | Serial.print("Moved: "); 92 | unsigned long smoved = Motor.stepsMoved(); 93 | Serial.println(smoved, DEC); 94 | } 95 | else { 96 | Serial.println("Got Begin!"); 97 | } 98 | 99 | } 100 | @endcode 101 | 102 | @param p_Func 103 | A pointer to a function taking a single byte argument 104 | 105 | */ 106 | 107 | 108 | void setMasterHandler( void(*p_Func)(uint8_t) ) { 109 | f_motSignal = p_Func; 110 | } 111 | 112 | void _fireCallback(uint8_t p_Param) { 113 | if( f_motSignal != 0 ) { 114 | f_motSignal(p_Param); 115 | } 116 | } 117 | 118 | 119 | /** Set Maximum Stepping Rate 120 | 121 | Sets the maximum rate at which steps can be taken. 122 | 123 | Due to the nature of the timing calculations, you are limited to one of the 124 | following choices: 5000, 4000, 2000, and 1000. Any other input will be 125 | ignored and result in no change. 126 | 127 | Please note: the maximum rate here defines how often the step interrupt 128 | service routine runs. The higher the rate you use, the greater the amount 129 | of CPU that will be utilized to run the stepper. At the maximum rate, over 130 | 50% of the available processing time of an Atmega328 is utilized at 16Mhz, 131 | while at the lowest rate, approximately 25% of the processing time is utilized. 132 | 133 | For more information on step timing, see the \ref steptiming "Stepping Cycle" section. 134 | 135 | This rate does not dictate the actual speed of specific moves, 136 | it defines the highest speed which is achievable for any kind of move. 137 | 138 | @param p_Rate 139 | The rate specified as a number of steps per second (5000, 4000, 2000, or 1000) 140 | */ 141 | 142 | uint8_t maxStepRate( unsigned int p_Rate ) { 143 | 144 | 145 | if( p_Rate != 10000 && p_Rate != 5000 && p_Rate != 4000 && p_Rate != 2000 && p_Rate != 1000 ) 146 | return(false); 147 | 148 | 149 | motor[0].maxStepRate(p_Rate); 150 | motor[1].maxStepRate(p_Rate); 151 | motor[2].maxStepRate(p_Rate); 152 | return(true); 153 | 154 | } 155 | 156 | /** Get Maximum Stepping Rate 157 | 158 | Returns the current maximum stepping rate in steps per second. m_curSampleTime is a static variable, therefore 159 | we can grab it from any of the motors. 160 | 161 | @return 162 | Maximum rate in steps per second 163 | */ 164 | 165 | unsigned int maxStepRate() { 166 | return( motor[0].maxStepRate() ); 167 | } 168 | 169 | 170 | /** Stop Immediately 171 | 172 | Immediately stops any movement in progress. 173 | 174 | Triggers the callback with the OM_MOT_DONE argument. 175 | */ 176 | 177 | void stopAllMotors() { 178 | 179 | // set motors not moving in async mode 180 | 181 | for (int i = 0; i < MOTOR_COUNT; i++) { 182 | motor[i].stop(); 183 | //update current position to EEPROM 184 | long tempPosition= motor[i].currentPos(); 185 | OMEEPROM::write(EE_POS_0 + (i) * EE_MOTOR_MEMORY_SPACE, tempPosition); 186 | } 187 | 188 | 189 | ISR_On = false; 190 | 191 | // signal completion 192 | _fireCallback(OM_MOT_DONE); 193 | // let go of interrupt cycle 194 | Timer1.detachInterrupt(); 195 | 196 | } 197 | 198 | /** Clear Steps Moved 199 | 200 | Clears the count of steps moved. Additionally, if the motor is currently 201 | running, any movement will be immediately stopped, and the callback will 202 | be executed with the OM_MOT_DONE argument. 203 | 204 | This method does NOT reset the home location for the motor. It does, however, 205 | reset any plan currently executing or previously executed. 206 | 207 | */ 208 | 209 | void clearAll() { 210 | 211 | // stop if currently running 212 | 213 | if( motor[0].running() || motor[1].running() || motor[2].running() ) 214 | stopAllMotors(); 215 | 216 | for (int i = 0; i < MOTOR_COUNT; i++){ 217 | 218 | motor[i].clear(); 219 | } 220 | } 221 | 222 | 223 | // execute an async move, when specifying a direction 224 | void startISR() { 225 | 226 | if ((motor[0].running() || motor[1].running() || motor[2].running())){ 227 | 228 | // is async control not already running? 229 | if( !ISR_On ) { 230 | 231 | _fireCallback(OM_MOT_MOVING); 232 | Timer1.initialize(motor[0].curSamplePeriod()); 233 | Timer1.attachInterrupt(_runISR); 234 | ISR_On = true; 235 | } // end if not running 236 | } 237 | 238 | } 239 | 240 | 241 | // our ISR that is run every time Timer1 triggers, controls stepping 242 | // of the motor 243 | 244 | void _runISR() { 245 | //PORTF |= (1 << motor[2].stpflg); 246 | //delayMicroseconds(1); 247 | 248 | 249 | //steps all motors at once 250 | for(int i = 0; i < MOTOR_COUNT; i++){ 251 | if(motor[i].running()){ 252 | motor[i].checkRefresh(); // Reset motor steps, cycles, error, etc for the new ISR run 253 | if (motor[i].checkStep()){ // 254 | byteFired |= (1 << motor[i].stpflg); 255 | } 256 | } // end if( motor[i].m_isRun 257 | 258 | } // end for loop 259 | 260 | 261 | 262 | PORTF |= byteFired; 263 | delayMicroseconds(1); 264 | PORTF &= ~byteFired; 265 | 266 | 267 | 268 | //resets the byteFired flag 269 | byteFired = 0; 270 | 271 | if (!(motor[0].running() || motor[1].running() || motor[2].running())){ 272 | stopAllMotors(); 273 | } 274 | 275 | //PORTF &= ~(1 << motor[2].stpflg); 276 | } 277 | 278 | 279 | 280 | -------------------------------------------------------------------------------- /Firmware/Motion_Engine/OM_Motor_Control.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | Motion Engine 5 | 6 | See dynamicperception.com for more information 7 | 8 | 9 | (c) 2008-2012 C.A. Church / Dynamic Perception LLC 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program. If not, see . 23 | 24 | 25 | */ 26 | 27 | 28 | /* 29 | 30 | ========================================= 31 | Motor control functions 32 | ========================================= 33 | 34 | */ 35 | 36 | const byte MT_COM_DIR1 = 50; 37 | const byte MT_COM_DIR2 = 100; 38 | 39 | void move_motor() { 40 | 41 | // do we revert back to "ready" or "waiting" if there 42 | // is nothing to do, or block for? - Based on master/slave status 43 | 44 | byte continue_state = (ComMgr.master() == true) ? ST_CLEAR : ST_BLOCK; 45 | 46 | // motor disabled? Do nothing. 47 | if( ! motor[0].enable() && !motor[1].enable() && !motor[2].enable() ) { 48 | Engine.state(continue_state); 49 | return; 50 | } 51 | 52 | for(int i = 0; i < MOTOR_COUNT; i++){ 53 | //only check the motors that are enabled 54 | if( motor[i].enable()){ 55 | //check to see if there's a shot delay for the motor 56 | if (!(motor[i].planLeadIn() > 0 && ((camera_fired <= motor[i].planLeadIn() && motor[i].planType() == SMS) || (motor[i].planType() != SMS && run_time <= motor[i].planLeadIn())))){ 57 | motor[i].programMove(); 58 | if( motor[i].planType() == SMS ) { 59 | // planned SMS move 60 | //motor[i].planRun(); 61 | // block camera while motor is moving 62 | Engine.state(ST_RUN); 63 | } 64 | else { 65 | // planned continuous move 66 | Engine.state(continue_state); 67 | } 68 | } 69 | } 70 | } 71 | //Start interrupt service routine to start motors moving 72 | startISR(); 73 | } 74 | 75 | 76 | // callback handler for OMComHandler class to handle trips on the common line 77 | // (if we're watching a common line for movement trips) 78 | 79 | void motor_com_line(unsigned int p_time) { 80 | if( p_time > MT_COM_DIR1 && p_time < MT_COM_DIR2 ){ 81 | motor[0].move(0, 1); 82 | motor[1].move(0, 1); 83 | motor[2].move(0, 1); 84 | } 85 | else if( p_time > MT_COM_DIR2 ){ 86 | motor[0].move(1, 1); 87 | motor[1].move(1, 1); 88 | motor[2].move(1, 1); 89 | } 90 | } 91 | 92 | /* 93 | byte motorSleep() 94 | 95 | Returns the sleep state of all motors, where the state of each motor is 96 | indicated by the boolean state of bits 0, 1, and 2 of the returned byte. 97 | 98 | */ 99 | 100 | byte motorSleep() { 101 | 102 | byte sleep_state = B000; 103 | 104 | for (byte i = 0; i < MOTOR_COUNT; i++) { 105 | if (motorSleep(i) == true) 106 | sleep_state |= (1 << i); 107 | } 108 | 109 | return sleep_state; 110 | } 111 | 112 | /* 113 | void motorSleep(byte p_motor, bool p_sleep) 114 | 115 | Sets and saves motor sleep state 116 | 117 | p_motor: Which motor to set the sleep state (0,1,2) 118 | p_sleep: Sleep state (true/false) 119 | 120 | */ 121 | 122 | void motorSleep(byte p_motor, bool p_sleep) { 123 | motor[p_motor].sleep(p_sleep); 124 | OMEEPROM::write(EE_SLEEP_0 + (p_motor * EE_MOTOR_MEMORY_SPACE), p_sleep); 125 | } 126 | 127 | /* 128 | byte motorSleep(byte p_motor) 129 | 130 | Returns the sleep state of the selected motor 131 | 132 | p_motor: Which motor to query the sleep state of (0,1,2) 133 | 134 | */ 135 | 136 | byte motorSleep(byte p_motor) { 137 | return motor[p_motor].sleep(); 138 | } 139 | 140 | 141 | /* 142 | void takeUpBackLash() 143 | 144 | This function checks which motors have backlash and take it up. 145 | This is determined by comparing their last direction to the direction 146 | they will need to move to get to their program stop position. 147 | 148 | */ 149 | void takeUpBacklash(){ 150 | takeUpBacklash(false); 151 | } 152 | 153 | void takeUpBacklash(boolean kf_move){ 154 | uint8_t wait_required = false; 155 | // Check each motor to see if it needs backlash compensation 156 | for (byte i = 0; i < MOTOR_COUNT; i++) { 157 | if (motor[i].programBackCheck() == true && motor[i].backlash() > 0) { 158 | // Indicate that a brief pause is necessary after starting the motors 159 | wait_required = true; 160 | 161 | // Set the motor microsteps to low resolution and increase speed for fastest takeup possible 162 | motor[i].ms(4); 163 | 164 | motor[i].contSpeed(motor[i].maxSpeed()); 165 | 166 | // Determine the direction of the programmed move 167 | uint8_t dir = (motor[i].stopPos() - motor[i].startPos()) > 0 ? 1 : 0; 168 | 169 | // Move the motor 1 step in that direction to force the backlash takeup 170 | motor[i].move(dir, 1); 171 | startISR(); 172 | 173 | } 174 | } 175 | 176 | // Can't wait when it's a keyframe move. For some reason this causes the controller to lock 177 | if (wait_required && !kf_move) { 178 | unsigned long time = millis(); 179 | const int BACKLASH_WAIT = 300; 180 | while (millis() - time < BACKLASH_WAIT){ 181 | // Wait for backlash takeup to finish 182 | } 183 | } 184 | 185 | // Re-set all the motors to their proper microstep settings 186 | for (byte i = 0; i < MOTOR_COUNT; i++) { 187 | motor[i].restoreLastMs(); 188 | 189 | // Print debug info if proper flag is set 190 | debug.funct("Microsteps: "); 191 | debug.functln(motor[i].ms()); 192 | } 193 | debug.functln("Out of loop and moving on!"); 194 | } 195 | 196 | 197 | /* 198 | void startProgramCom() 199 | 200 | Runs all pre-program checks after a start program command is received from a master device. 201 | Actual motor movement is started by calling startProgram() at the end of this function. 202 | */ 203 | 204 | void startProgramCom() { 205 | 206 | bool was_pause = pause_flag; 207 | pause_flag = false; 208 | 209 | // Don't perform backlash checks or other start of move operations if the program was paused or is currently running 210 | if (!running && !was_pause) { 211 | 212 | // Reset the shot counter to 0. If the user presses the "Fire Camera" button in the joystick screen of the app, it may be a non-zero number. 213 | clearShotCounter(); 214 | 215 | // Reset the program completion flag 216 | program_complete = false; 217 | ping_pong_time = 0; 218 | 219 | takeUpBacklash(); 220 | 221 | // Re-set all the motors to their proper microstep settings 222 | for (byte i = 0; i < MOTOR_COUNT; i++) { 223 | if (!graffikMode()) 224 | msAutoSet(i); 225 | 226 | // Print debug info if proper flag is set 227 | debug.funct("Microsteps: "); 228 | debug.functln(motor[i].ms()); 229 | 230 | } 231 | 232 | // When starting an SMS move, if we're only making small moves, set each motor's speed no faster than necessary to produce the smoothest motion possible 233 | if (Motors::planType() == SMS) { 234 | 235 | // Determine the max time in seconds allowed for moving the motors 236 | float max_move_time = (Camera.intervalTime() - Camera.triggerTime() - Camera.delayTime() - Camera.focusTime()) / MILLIS_PER_SECOND; 237 | // If there's lots of time for moving, only use 1 second so we don't waste battery life getting to the destination 238 | if (max_move_time > 0.5) 239 | max_move_time = 0.5; 240 | // Determine the maximum number of steps each motor needs to move. For short move, throttle the speed to avoid jerking of the rig. 241 | for (byte i = 0; i < MOTOR_COUNT; i++) { 242 | int steps_per_move = motor[i].getTopSpeed(); 243 | if (steps_per_move < 500) { 244 | // Only use 50% of the maximum move time to allow for accel and decel phases 245 | motor[i].contSpeed((float)steps_per_move / (max_move_time * 0.5)); 246 | } 247 | } 248 | } 249 | 250 | // If we're starting a video move, fire the camera trigger pin to start the video camera 251 | if (Motors::planType() == CONT_VID) { 252 | Camera.expose(); 253 | unsigned long time = millis(); 254 | while (millis() - time < (MILLIS_PER_SECOND * 1.5)) 255 | { 256 | // Wait a second and a half for the video to start before starting the move. 257 | } 258 | } 259 | }//end if (!running && !was_pause) 260 | 261 | // Don't start a new program if one is already running 262 | if (!running) { 263 | const String MOTOR = "Motor "; 264 | debug.functln(MOTOR + "dist: "); 265 | for (byte i = 0; i < MOTOR_COUNT; i++){ 266 | debug.functln(motor[i].stopPos() - motor[i].currentPos()); 267 | } 268 | debug.functln(MOTOR + "start:"); 269 | for (byte i = 0; i < MOTOR_COUNT; i++){ 270 | debug.functln(motor[i].startPos()); 271 | } 272 | debug.functln(MOTOR + "stop:"); 273 | for (byte i = 0; i < MOTOR_COUNT; i++){ 274 | debug.functln(motor[i].stopPos()); 275 | } 276 | debug.functln(MOTOR + "current:"); 277 | for (byte i = 0; i < MOTOR_COUNT; i++){ 278 | debug.functln(motor[i].currentPos()); 279 | } 280 | debug.functln(MOTOR + "travel:"); 281 | for (byte i = 0; i < MOTOR_COUNT; i++){ 282 | debug.functln(motor[i].planTravelLength()); 283 | } 284 | 285 | //if it was paused and not SMS then recalculate move from pause time 286 | if (was_pause && Motors::planType() != SMS){ 287 | for (byte i = 0; i < MOTOR_COUNT; i++){ 288 | if (motor[i].enable()) 289 | motor[i].resumeMove(); 290 | } 291 | } 292 | 293 | startProgram(); 294 | } 295 | } 296 | 297 | /* 298 | byte validateProgram() 299 | 300 | Checks all motors to see if they can achieve the speed required given the current program parameters. 301 | 302 | */ 303 | 304 | byte validateProgram() { 305 | 306 | byte validation = B00000000; 307 | 308 | // If a motor is valid, mark that bit true 309 | for (byte i = 0; i < MOTOR_COUNT; i++) { 310 | if (validateProgram(i) == true) 311 | validation |= (1 << i); 312 | } 313 | 314 | // Return byte indicating status of all three motors 315 | return validation; 316 | } 317 | 318 | /* 319 | byte validateProgram(byte p_motor) 320 | 321 | Checks specified motor to see if it can achieve the speed required given the current program parameters. 322 | 323 | p_motor: Motor to check (0 through MOTOR_COUNT) 324 | 325 | */ 326 | 327 | byte validateProgram(byte p_motor) { 328 | return validateProgram(p_motor, false); 329 | } 330 | 331 | 332 | /* 333 | byte validateProgram(byte p_motor, bool p_autosteps) 334 | 335 | Checks specified motor to see if it can achieve the speed required given the current program parameters. 336 | 337 | p_motor: Motor to check (0 through MOTOR_COUNT) 338 | p_autosteps: Optional parameter. Function will return required microstep setting instead of true on success and 255 instead of false upon failure. 339 | 340 | */ 341 | 342 | byte validateProgram(byte p_motor, bool p_autosteps) { 343 | // The microstepping cutoff values below are in 16th steps 344 | const int MAX_CUTOFF = 16000; 345 | const int QUARTER_CUTOFF = 8000; 346 | const int EIGHTH_CUTOFF = 4000; 347 | float comparison_speed; 348 | float max_time_per_move; 349 | float steps_per_move; 350 | 351 | // When the controller is in external intervalometer mode, rather than determining the step speed based upon the given interval, 352 | // the interval will be determined based upon movement at full speed in 8th stepping mode. 353 | if (external_intervalometer) { 354 | comparison_speed = 8000.0; // All external intervalometer moves will run at top speed in 8th stepping mode 355 | steps_per_move = motor[p_motor].getTopSpeed(); // Maximum number of steps per move 356 | max_time_per_move = (steps_per_move / comparison_speed) * MILLIS_PER_SECOND; // Max time in milliseconds 357 | unsigned long new_interval = max_time_per_move - (float)(Camera.delayTime() + Camera.triggerTime() + Camera.focusTime()); // Minimum camera interval 358 | Camera.intervalTime(new_interval); 359 | 360 | // Always run in eight steps for external intervalometer mode 361 | if (p_autosteps) 362 | return EIGHTH; 363 | else 364 | return 1; 365 | } 366 | 367 | // For time lapse SMS mode 368 | if (motor[p_motor].planType() == SMS) { 369 | 370 | // Max time in seconds 371 | float max_time_per_move = (float)(Camera.intervalTime() - Camera.delayTime() - Camera.triggerTime() - Camera.focusTime()) / MILLIS_PER_SECOND; 372 | 373 | 374 | // The "topSpeed" variable in SMS mode is actually the number of steps per move during the constant speed segment 375 | steps_per_move = motor[p_motor].getTopSpeed(); 376 | 377 | comparison_speed = steps_per_move / (float)max_time_per_move; 378 | 379 | } 380 | 381 | // For time lapse continuous mode and video continuous mode 382 | else if (motor[p_motor].planType() != SMS) { 383 | comparison_speed = motor[p_motor].getTopSpeed(); 384 | } 385 | 386 | // USB print the debug value, if necessary 387 | debug.funct("Top speed requested: "); 388 | debug.functln(comparison_speed); 389 | 390 | // Check the comparison speed against the cutoff values and select the appropriate microstepping setting 391 | // If the requested speed is too high, send error value, don't change microstepping setting 392 | if (comparison_speed >= MAX_CUTOFF ) { 393 | debug.functln("Excessive speed requested"); 394 | return 0; 395 | } 396 | else { 397 | // Return the appropriate microstep value if called from msAutoSet(), otherwise return true for OK 398 | if (p_autosteps) { 399 | if (comparison_speed >= QUARTER_CUTOFF && comparison_speed < MAX_CUTOFF) 400 | return QUARTER; 401 | else if (comparison_speed < QUARTER_CUTOFF && comparison_speed > EIGHTH_CUTOFF) 402 | return EIGHTH; 403 | else 404 | return SIXTHEENTH; 405 | } 406 | else 407 | return 1; 408 | } 409 | 410 | } 411 | 412 | /* 413 | byte msAutoSet(uint8_t p_motor_number) 414 | 415 | Set the appropriate microstep value for the motor based upon currently set program move parameters. 416 | 417 | p_motor_number: motor to modify microstepping 418 | 419 | */ 420 | 421 | byte msAutoSet(uint8_t p_motor) { 422 | return msAutoSet(p_motor, false); 423 | } 424 | 425 | byte msAutoSet(uint8_t p_motor, boolean validateOnly) { 426 | debug.functln("Trying to auto-set microsteps"); 427 | unsigned long time = millis(); 428 | byte microsteps; 429 | 430 | // Don't change the microstep value if the motor or program is running 431 | if (!running && !motor[p_motor].running()) { 432 | 433 | // Get program validation info 434 | microsteps = validateProgram(p_motor, true); 435 | 436 | if (validateOnly){ 437 | if (microsteps == false) 438 | return 0; 439 | else 440 | return 1; 441 | } 442 | 443 | // Return an error code of 255 if called from msAutoSet(), since a 0 error is given when the routine cannot be run 444 | if (microsteps == false) 445 | return 255; 446 | 447 | // Otherwise set the appropraite microstep setting and report the new value back to the master device 448 | else 449 | motor[p_motor].ms(microsteps); 450 | 451 | // Save the microstep settings 452 | OMEEPROM::write(EE_MS_0 + (p_motor * EE_MOTOR_MEMORY_SPACE), microsteps); 453 | 454 | // USB print the debug value, if necessary 455 | debug.funct("Requested Microsteps: "); 456 | debug.functln(microsteps); 457 | return microsteps; 458 | 459 | } 460 | 461 | // If the motor or program is running and a report is requested, return 0 to indicate that the auto-set routine was not completed 462 | else { 463 | debug.functln("Motors are running, can't auto-set microsteps"); 464 | return false; 465 | } 466 | } 467 | 468 | /* 469 | void joystickSet(byte p_input) 470 | 471 | Sets joystick mode on or off. If turning off joystick mode, watchdog mode is also turned off automatically. 472 | 473 | p_input: True or false setting. 474 | 475 | */ 476 | 477 | void joystickSet(byte p_input) { 478 | joystick_mode = p_input; 479 | 480 | debug.ser("Joystick: "); 481 | debug.serln(String(joystick_mode)); 482 | 483 | // Set the speed of all motors to zero when turning on joystick mode to prevent runaway motors 484 | if (joystick_mode){ 485 | for (byte i = 0; i < MOTOR_COUNT; i++) 486 | motor[i].contSpeed(0); 487 | } 488 | // If we're exiting joystick mode, turn off the joystick watchdog mode 489 | else if (!joystick_mode) { 490 | watchdogMode(false); 491 | } 492 | } 493 | 494 | /** 495 | byte joystickSet() 496 | 497 | Returns joystick mode status 498 | 499 | */ 500 | 501 | byte joystickSet() { 502 | return joystick_mode; 503 | } 504 | 505 | 506 | /** 507 | void pingPongMode(byte p_input) 508 | 509 | Sets ping-pong mode on or off. 510 | 511 | p_input: True or false setting. 512 | 513 | */ 514 | 515 | void pingPongMode(byte p_input) { 516 | 517 | // Ignore non-true/false input 518 | if (p_input != 0 && p_input != 1) 519 | return; 520 | 521 | ping_pong_mode = p_input; 522 | } 523 | 524 | 525 | /** 526 | byte pingPongMode() 527 | 528 | Returns ping-pong mode status 529 | 530 | */ 531 | 532 | byte pingPongMode() { 533 | return ping_pong_mode; 534 | } 535 | 536 | byte keepAliveMode(){ 537 | return keep_camera_alive; 538 | } 539 | 540 | void setJoystickSpeed(int p_motor, float p_speed){ 541 | 542 | float old_speed = motor[p_motor].desiredSpeed(); 543 | float new_speed = p_speed; 544 | 545 | // Don't allow the speed to be set higher than the maximum 546 | if (abs(new_speed) > (float)motor[p_motor].maxSpeed()) { 547 | if (new_speed < 0.0) 548 | new_speed = (float)motor[p_motor].maxSpeed() * -1.0; 549 | else 550 | new_speed = motor[p_motor].maxSpeed(); 551 | } 552 | 553 | // Set speed 554 | motor[p_motor].contSpeed(new_speed); 555 | 556 | // Start new move if starting from a stop or there is a direction change 557 | if (abs(old_speed) < 1 && abs(new_speed) > 1 || ((old_speed / abs(old_speed)) != (new_speed / abs(new_speed)) && abs(new_speed) > 1)){ 558 | byte dir; 559 | if (new_speed > 1) 560 | dir = 1; 561 | else if (new_speed < 1) 562 | dir = 0; 563 | 564 | motor[p_motor].continuous(true); 565 | motor[p_motor].move(dir, 0); 566 | startISR(); 567 | debug.serln("Mot.13 - Auto-starting continuous move"); 568 | } 569 | 570 | // If all the motors are commanded to zero speed, disable watchdog until a new non-zero speed is set 571 | if (p_speed == 0){ 572 | bool allStopped = true; 573 | for (byte i = 0; i < MOTOR_COUNT; i++){ 574 | if (motor[i].desiredSpeed() != 0){ 575 | allStopped = false; 576 | break; 577 | } 578 | } 579 | if (allStopped){ 580 | watchdog_active = false; 581 | } 582 | 583 | } 584 | // If watchdog mode is enabled and the speed is non-zero, activate watchdog 585 | else if(watchdogMode()){ 586 | watchdog_active = true; 587 | } 588 | } 589 | 590 | /** Reverse Move 591 | 592 | Stops the motors, switches the start and stop positions, then restarts the motors. 593 | Moves only if ping_pong_mode is enabled. 594 | */ 595 | 596 | void reverseStartStop(){ 597 | debug.serln("reverseStartStop()"); 598 | 599 | for (int i = 0; i < MOTOR_COUNT; i++){ 600 | //Switches start and stop positions 601 | long curStart = motor[i].startPos(); 602 | long curStop = motor[i].stopPos(); 603 | motor[i].startPos(curStop); 604 | motor[i].stopPos(curStart); 605 | } 606 | 607 | // Swap key point order 608 | for (int i = 0; i < MOTOR_COUNT; i++){ 609 | KeyFrames::setAxis(i); 610 | int count = kf[i].getKFCount(); 611 | 612 | // Don't try to reverse if there's nothing to reverse 613 | if (count == 0){ 614 | continue; 615 | } 616 | 617 | // Allocate space for temporary array 618 | float* tempAbscissa = (float*)malloc(count * sizeof(float)); 619 | float* tempPos = (float*)malloc(count * sizeof(float)); 620 | float* tempVel = (float*)malloc(count * sizeof(float)); 621 | 622 | // Copy existing array to temporary arr. Don't reverse abscissa order. 623 | float maxAbscissa = kf[i].getXN(count-1); 624 | for (int j = 0; j < count; j++){ 625 | // Need to mirror abscissas rather than simply reversing them 626 | tempAbscissa[j] = maxAbscissa - kf[i].getXN((count - 1) - j); 627 | tempPos[j] = kf[i].getFN((count - 1) - j); 628 | // Invert velocities 629 | tempVel[j] = -kf[i].getDN((count - 1) - j); 630 | } 631 | 632 | // Clear existing key frames 633 | kf[i].resetXN(); 634 | kf[i].resetFN(); 635 | kf[i].resetDN(); 636 | kf[i].setKFCount(count); 637 | 638 | // Repopulate in reverse order 639 | for (int j = 0; j < count; j++){ 640 | kf[i].setXN(tempAbscissa[j]); 641 | kf[i].setFN(tempPos[j]); 642 | kf[i].setDN(tempVel[j]); 643 | } 644 | 645 | // Free memory used in tempoary arrays 646 | free(tempAbscissa); 647 | free(tempPos); 648 | free(tempVel); 649 | } 650 | } 651 | 652 | 653 | 654 | 655 | 656 | 657 | -------------------------------------------------------------------------------- /Firmware/Motion_Engine/OM_Motor_Travel.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | Motion Engine 5 | 6 | See dynamicperception.com for more information 7 | 8 | 9 | (c) 2008-2012 C.A. Church / Dynamic Perception LLC 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program. If not, see . 23 | 24 | 25 | */ 26 | 27 | 28 | /* 29 | 30 | ========================================= 31 | Motor traveling functions 32 | ========================================= 33 | 34 | 35 | */ 36 | 37 | 38 | void sendAllToStart() { 39 | 40 | // If any of the motors are currently running, don't start the motors moving 41 | for (byte i = 0; i < MOTOR_COUNT; i++) { 42 | if (motor[i].running()) { 43 | return; 44 | } 45 | } 46 | 47 | for (byte i = 0; i < MOTOR_COUNT; i++) { 48 | sendToStart(i); 49 | } 50 | } 51 | 52 | void sendToStart(uint8_t p_motor) { 53 | 54 | // Determine whether this move will induce backlash that needs to be taken up before starting the program move 55 | uint8_t program_dir = (motor[p_motor].stopPos() - motor[p_motor].startPos()) > 0 ? 1 : 0; 56 | uint8_t this_move_dir = (motor[p_motor].startPos() - motor[p_motor].currentPos()) > 0 ? 1 : 0; 57 | 58 | if (program_dir != this_move_dir) 59 | motor[p_motor].programBackCheck(true); 60 | else 61 | motor[p_motor].programBackCheck(false); 62 | 63 | // Move at the maximum motor speed 64 | motor[p_motor].ms(4); 65 | motor[p_motor].contSpeed(motor[p_motor].maxSpeed()); 66 | 67 | // Start the move 68 | motor[p_motor].moveToStart(); 69 | startISR(); 70 | motor[p_motor].setSending(true); 71 | } 72 | 73 | void sendToStop(uint8_t p_motor){ 74 | // Move at the maximum motor speed 75 | motor[p_motor].ms(4); 76 | motor[p_motor].contSpeed(motor[p_motor].maxSpeed()); 77 | motor[p_motor].moveToStop(); 78 | startISR(); 79 | motor[p_motor].setSending(true); 80 | } 81 | 82 | void sendTo(uint8_t p_motor, long p_pos){ 83 | sendTo(p_motor, p_pos, false); 84 | } 85 | 86 | void sendTo(uint8_t p_motor, long p_pos, boolean kf_move){ 87 | 88 | // When not in Graffik Mode (i.e. App mode), use the lowest microsteps 89 | if (!kf_move){ 90 | motor[p_motor].ms(4); 91 | // Adjust the send location to match new microsteps 92 | p_pos *= ((float)motor[p_motor].ms() / (float)motor[p_motor].lastMs()); 93 | } 94 | 95 | // Move at the maximum motor speed 96 | debug.funct("Sending motor "); 97 | debug.funct(p_motor); 98 | debug.funct(" to position "); 99 | debug.functln(p_pos); 100 | motor[p_motor].contSpeed(motor[p_motor].maxSpeed()); 101 | motor[p_motor].moveTo(p_pos, true); 102 | debug.funct("Speed: "); 103 | debug.functln(motor[p_motor].contSpeed()); 104 | debug.funct("Continuous: "); 105 | debug.functln(motor[p_motor].continuous()); 106 | startISR(); 107 | if (!kf_move) 108 | motor[p_motor].setSending(true); 109 | } -------------------------------------------------------------------------------- /Firmware/Motion_Engine/README.txt: -------------------------------------------------------------------------------- 1 | This is the Motion Engine for the Arduino/nanoMoCo Platform. 2 | 3 | Version: 1.0.7 4 | 5 | More information can be found at http://www.dynamicperception.com/ 6 | 7 | It is (c) 2008-2013 C.A. Church / Dynamic Perception LLC 8 | 9 | See LICENSE.txt for licensing information. 10 | 11 | -------------------------------------------------------------------------------- /Firmware/Motion_Engine/Sample Commands.txt: -------------------------------------------------------------------------------- 1 | Commands 2 | 3 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x01 0x03 0x01 0x01 - Enable motor 1 4 | 5 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x02 0x03 0x01 0x01 - Enable motor 2 6 | 7 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x03 0x03 0x01 0x01 - Enable motor 3 8 | 9 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x03 0x06 0x01 0x10 - MicroStep level 16 motor 3 10 | 11 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x03 0x08 0x01 0x01 - direction 1 motor 3 12 | 13 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x03 0x0B 0x00 - send motor 3 home 14 | 15 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x01 0x0F 0x05 0x01 0x00 0x00 0x03 0xE8 - 1 simple move 1000 steps 16 | 17 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x02 0x0F 0x05 0x01 0x00 0x00 0x03 0xE8 - 2 simple move 1000 steps 18 | 19 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x03 0x0F 0x05 0x01 0x00 0x00 0x03 0xE8 - 3 simple move 1000 steps 20 | 21 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x01 0x66 0x00 - read motor 1 ms 22 | 23 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x04 0x02 0x01 0x01 - Enable Camera 1 24 | 25 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x04 0x0A 0x04 0x00 0x00 0x03 0xE8 - set interval time to 1 second 26 | 27 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x04 0x06 0x02 0x00 0x10 - max shots 16 28 | 29 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x01 0x0A 0x02 0x00 0xFF - sets steps per interval motor 1 30 | 31 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x01 0x07 0x02 0x0F 0xFF - set max step speed motor 1 32 | 33 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x00 0x02 0x00 - start program 34 | 35 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x00 0x04 0x00 - stop program 36 | 37 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x00 0x6B 0x00 - voltage level 38 | 39 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x00 0x6C 0x00 - current level 40 | 41 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x01 0x0F 0x05 0x01 0x00 0x00 0x3B 0x60 42 | 43 | Get position 44 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x01 0x6A 0x00 45 | 46 | Set start position 47 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x01 0x10 0x04 0x00 0x00 0x07 0xd0 48 | 49 | Set stop position 50 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x01 0x11 0x04 0x00 0x00 0x13 0x88 51 | 52 | Set SMS mode 53 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x00 0x22 0x01 0x00 54 | 55 | Set Ramping mode - quadratic 56 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x01 0x12 0x01 0x02 57 | 58 | Set max shots 59 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x04 0x06 0x02 0x00 0x10 60 | 61 | Set lead-in shots 62 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x01 0x13 0x00 0x01 63 | 64 | Set program accel phase 65 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x01 0x15 0x04 0x00 0x00 0x00 0x03 66 | 67 | Set program decel phase 68 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x01 0x16 0x04 0x00 0x00 0x00 0x03 69 | 70 | Send motor to start position 71 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x01 0x17 0x00 72 | 73 | Start program 74 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x00 0x02 0x00 75 | 76 | Stop program 77 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x00 0x04 0x00 78 | 79 | Stop motor 80 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x01 0x04 0x00 81 | 82 | Set home here 83 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x01 0x09 0x00 84 | 85 | Set end here 86 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x01 0x0A 0x00 87 | 88 | Send motor home 89 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x01 0x0B 0x00 90 | 91 | Send motor to end position 92 | 0x00 0x00 0x00 0x00 0x00 0xFF 0x03 0x01 0x0C 0x00 93 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Motion Engine Firmware for nanoMoCo / Arduino 2 | ============================================= 3 | 4 | Version: 1.0.7 5 | --------------- 6 | 7 | This is the Motion Engine for the Arduino/nanoMoCo Platform. 8 | 9 | Version: 1.0.7 10 | 11 | ### Required Libraries 12 | 13 | You must install the following libraries to compile the MotionEngine: 14 | 15 | * [OMLibraries v1.13](https://github.com/DynamicPerception/OMLibraries/tree/v1.13) 16 | * [MsTimer2](http://www.pjrc.com/teensy/td_libs_MsTimer2.html) 17 | * [TimerOne](http://code.google.com/p/arduino-timerone/downloads/list) 18 | 19 | 20 | For more information on installing libraries in Arduino, see [Arduino Libraries Guide](http://arduino.cc/en/Guide/Libraries). 21 | 22 | ### Uploading to nanoMoCo 23 | 24 | Key tips for uploading to the nanoMoCo: 25 | 26 | * Ensure you select 'Arduino Uno' as the Board Type 27 | * You have 8 seconds after powering on the nanoMoCo to begin uploading firmware 28 | * You may only upload firmware over the RS485 interface 29 | 30 | ### Bootloader 31 | 32 | This bundle includes a bootloader for the nanoMoCo, or any ATMega328p device, to upload firmware over RS485. Play with at will. 33 | 34 | ### More Information 35 | 36 | More information can be found at http://www.dynamicperception.com/ 37 | 38 | ### Copyright and License 39 | 40 | (c) 2008-2013 C.A. Church / Dynamic Perception LLC 41 | 42 | The Motion Engine firmware is distributed under a GPLv3 License. See LICENSE.txt for licensing information. 43 | 44 | -------------------------------------------------------------------------------- /Web Updater/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | MX2 Motion Controller 16 | 17 | Standard MX2 Motion Controller as Supplied by DP 18 | 19 | -C%c;-v;-patmega328p;-carduino;-b57600;-D;-P%p;-Uflash:w:%f:i 20 | 21 | 22 | 23 | 24 | 25 | 0.94 W 26 | 27 | New features and fixed some bugs 28 | 29 | http://download.dynamicperception.com/dpwu/mx2/0.94W.hex 30 | 31 | 32 | 33 | 34 | 35 | 0.93 W 36 | 37 | New features and fixed some bugs 38 | 39 | http://download.dynamicperception.com/dpwu/mx2/0.93.hex 40 | 41 | 42 | 43 | 44 | 45 | 0.92 Beta 46 | 47 | Adds a bunch of new features 48 | 49 | http://download.dynamicperception.com/dpwu/mx2/0.92.hex 50 | 51 | 52 | 53 | 54 | 55 | 0.911 Beta 56 | 57 | Adds a bunch of new features 58 | 59 | http://download.dynamicperception.com/dpwu/mx2/0.911.hex 60 | 61 | 62 | 63 | 64 | 65 | 0.90 66 | 67 | Adds a bunch of new features 68 | 69 | http://download.dynamicperception.com/dpwu/mx2/0.90.hex 70 | 71 | 72 | 73 | 74 | 75 | 0.834 76 | 77 | Adds a bunch of new features 78 | 79 | http://download.dynamicperception.com/dpwu/mx2/0.834.hex 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | DIY DollyShield w/ Arduino Uno 90 | 91 | DIY DollyShield Mounted on an Arduino Uno 92 | 93 | -C%c;-v;-patmega328p;-carduino;-D;-P%p;-Uflash:w:%f:i 94 | 95 | 96 | 97 | 98 | 99 | 0.93 W 100 | 101 | New features and fixed some bugs 102 | 103 | http://download.dynamicperception.com/dpwu/mx2/0.93.hex 104 | 105 | 106 | 107 | 108 | 109 | 0.92 Beta 110 | 111 | Adds a bunch of new features 112 | 113 | http://download.dynamicperception.com/dpwu/mx2/0.92.hex 114 | 115 | 116 | 117 | 118 | 119 | 0.911 Beta 120 | 121 | Adds a bunch of new features 122 | 123 | http://download.dynamicperception.com/dpwu/mx2/0.911.hex 124 | 125 | 126 | 127 | 128 | 129 | 0.90 130 | 131 | Adds a bunch of new features 132 | 133 | http://download.dynamicperception.com/dpwu/mx2/0.90.hex 134 | 135 | 136 | 137 | 138 | 139 | 0.834 140 | 141 | Adds a bunch of new features 142 | 143 | http://download.dynamicperception.com/dpwu/mx2/0.834.hex 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | NMX 3-Axis Stepper Controller 154 | 155 | nanoMoCo Stepper Driver/Controller 156 | -C%c;-v;-pat90usb1287;-cavr109;-D;-P%p;-b57600;-Uflash:w:%f:i 157 | 158 | 159 | 160 | 161 | 0.54 Beta 162 | 163 | 3-28-16: 164 | 165 | Added command 1-3.130 -- This command checks whether the the specified motor can achieve the maximum velocity necessary for the currently set 2-point program. 166 | 167 | 168 | 169 | http://download.dynamicperception.com/dpwu/nmx/0.54.hex 170 | 171 | 172 | 173 | 174 | 175 | 0.55 Beta 176 | 177 | 3-30-16: 178 | 179 | Fixed unreliable camera test mode. 180 | 181 | 182 | 183 | http://download.dynamicperception.com/dpwu/nmx/0.55.hex 184 | 185 | 186 | 187 | 188 | 189 | 0.56 Beta 190 | 191 | 4-8-16: 192 | 193 | Fixed ping-pong timing issue. Added saving of motor units. 194 | 195 | 196 | 197 | http://download.dynamicperception.com/dpwu/nmx/0.56.hex 198 | 199 | 200 | 201 | 202 | 203 | 0.57 Beta 204 | 205 | 4-11-16: 206 | 207 | Added saving feature for gearbox and platform ratio values 208 | 209 | 210 | 211 | http://download.dynamicperception.com/dpwu/nmx/0.57.hex 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 0.58 Beta 221 | 222 | 223 | 224 | 4-14-16: 225 | 226 | 227 | 228 | Fixed missing responses for motor units, gbox ratio, and platform ratio setting commands. 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | http://download.dynamicperception.com/dpwu/nmx/0.58.hex 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | Development Firmware - NMX 253 | 254 | Development firmware for the NMX controller. These are not stable releases. 255 | 256 | -C%c;-v;-pat90usb1287;-cavr109;-D;-P%p;-b57600;-Uflash:w:%f:i 257 | 258 | 259 | 260 | 261 | 262 | 0.0.001 Key Frame Test 263 | 264 | Test of key frame functionality 265 | 266 | http://download.dynamicperception.com/dpwu/nmx/key_frame_test_0.01.hex 267 | 268 | 269 | 270 | 271 | 272 | 0.0.002 Key Frame Test 273 | 274 | Added some more KF query commands 275 | 276 | http://download.dynamicperception.com/dpwu/nmx/key_frame_test_0.02.hex 277 | 278 | 279 | 280 | 281 | 282 | 0.0.003 Key Frame Test 283 | 284 | 11-3-15: 285 | 286 | Added continuous video time command 5.17 287 | 288 | Abscissas for SMS mode now raw key frame numbers (instead of x1000 multiplied) 289 | 290 | 291 | 292 | http://download.dynamicperception.com/dpwu/nmx/key_frame_test_0.03.hex 293 | 294 | 295 | 296 | 297 | 298 | 0.0.004 Key Frame Test 299 | 300 | 11-4-15: 301 | 302 | Fixed microstep issues. 303 | 304 | 305 | 306 | http://download.dynamicperception.com/dpwu/nmx/key_frame_test_0.04.hex 307 | 308 | 309 | 310 | 311 | 312 | 0.0.005 Key Frame Test 313 | 314 | 11-10-15: 315 | 316 | Fixed KF percent complete query. 317 | 318 | 319 | 320 | http://download.dynamicperception.com/dpwu/nmx/key_frame_test_0.05.hex 321 | 322 | 323 | 324 | 325 | 326 | 0.0.006 327 | 328 | 12-10-15: 329 | 330 | Rollback to 0.004, but with negative runaway bug fix and no limit saving. 331 | 332 | 333 | 334 | http://download.dynamicperception.com/dpwu/nmx_dev/0.006.hex 335 | 336 | 337 | 338 | 339 | 340 | 0.0.007 341 | 342 | 12-15-15: 343 | 344 | Merged in some old changes. Needs to be tested for stability. 345 | 346 | 347 | 348 | http://download.dynamicperception.com/dpwu/nmx_dev/0.007.hex 349 | 350 | 351 | 352 | 353 | 354 | 0.0.007.48 355 | 356 | 2-5-16: 357 | 358 | Added USB reset feature. Added serial commands for setting and getting intervalometer mode (camera commands 13 and 112). 359 | 360 | 361 | 362 | http://download.dynamicperception.com/dpwu/nmx_dev/0.48.hex 363 | 364 | 365 | 366 | 367 | 368 | 0.0.007.1 Ping-pong Flag Test 369 | 370 | 2-12-16: 371 | 372 | Added ping-pong flag for running state query. 373 | 374 | 375 | 376 | http://download.dynamicperception.com/dpwu/nmx_dev/ping_pong_test.hex 377 | 378 | 379 | 380 | 381 | 382 | 383 | 0.0.008 384 | 385 | 2-19-16: 386 | 387 | Added enhanched status reporting. 388 | 389 | 390 | 391 | http://download.dynamicperception.com/dpwu/nmx_dev/0.008.hex 392 | 393 | 394 | 395 | 396 | 397 | 0.53 Test 398 | 399 | 3-8-16: 400 | 401 | Various status reporting bug fixes. 402 | 403 | 404 | 405 | http://download.dynamicperception.com/dpwu/nmx_dev/0.53.hex 406 | 407 | 408 | 409 | 410 | 411 | 0.53.2 Test 412 | 413 | 3-10-16: 414 | 415 | Allowing new status query during joystick mode 416 | 417 | 418 | 419 | http://download.dynamicperception.com/dpwu/nmx_dev/0.53.2.hex 420 | 421 | 422 | 423 | 424 | 425 | 0.53.3 Test 426 | 427 | 3-17-16: 428 | 429 | Fixed 2-point end of program bug. 430 | 431 | 432 | 433 | http://download.dynamicperception.com/dpwu/nmx_dev/0.53.3.hex 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | NanoMoco DIY 1 Axis 444 | 445 | nanoMoCo Stepper Driver/Controller 446 | -C%c;-v;-patmega328p;-carduino;-D;-P%p;-Uflash:w:%f:i 447 | 448 | 449 | 450 | 451 | 1.07 Beta 452 | 453 | First Public Beta Release, Required for use with Graffik 1.024 454 | 455 | http://download.dynamicperception.com/dpwu/nmx_legacy/1.07.hex 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | MX3 Motion Controller 467 | 468 | MX3 3-Axis Motion Controller 469 | 470 | -C%c;-v;-pat90usb1287;-cavr109;-D;-P%p;-b57600;-Uflash:w:%f:i 471 | 472 | 473 | 474 | 475 | 476 | 1.10.2 477 | 478 | Fixed shots/hr estimate resetting bug. Fixed MUP functionality. Added dynamic updating of dist/hr when shots/hr is adjusted. 479 | 480 | http://download.dynamicperception.com/dpwu/mx3/1.10.2.hex 481 | 482 | 483 | 484 | 485 | 486 | 1.10.1 487 | 488 | Fixed value bounding bugs in shots and distance estimator tools. Fixed memory reset bug. 489 | 490 | http://download.dynamicperception.com/dpwu/mx3/1.10.1.hex 491 | 492 | 493 | 494 | 495 | 496 | 1.10 497 | 498 | Added EZ mode. Added dynamic voltage compensation to maintain motor speed. Improved speed / distance calculation accuracy. Added units indicators. Added distance/hr and shots/hr estimators. Added setting of speed by percent power. Changed nomenclature for "Rising" and "Falling" to "Ending" and "Beginning". Changed nomenclature of "Cold Mode" to "NVD Auto-Off". Added pause function for aux I/O. Added setting of each speed decimal place. All motors are enabled by default after factory reset. 499 | 500 | http://download.dynamicperception.com/dpwu/mx3/1.10.hex 501 | 502 | 503 | 504 | 505 | 506 | 1.09 507 | 508 | Added a motor ramping to prevent tripping the battery when starting the program and during direction changes. Added I/O mode that allows the user to stop the motors but have the camera continue shooting. 509 | 510 | http://download.dynamicperception.com/dpwu/mx3/1.09.hex 511 | 512 | 513 | 514 | 515 | 516 | 1.08 517 | 518 | Added timer, fixed ramp and lead in issues, fixed I/O debouncing, reduced the problem of tripping the battery when reversing direction. 519 | 520 | http://download.dynamicperception.com/dpwu/mx3/1.08.hex 521 | 522 | 523 | 524 | 525 | 526 | 1.06 527 | 528 | Change the manual move to allow for a hold to move option and changed the speed increments. Fixed the errors occuring with the Aux I/O. Change the root menu so that if the user is currently on a motor screen and hits select they will jump to the root menu of that motor instead of the main root menu. 529 | 530 | http://download.dynamicperception.com/dpwu/mx3/1.06.hex 531 | 532 | 533 | 534 | 535 | 536 | 1.05 537 | 538 | Added VFD dimming menu. Fixed flickers in cursor on various screens. Added menu wrapping in both directions. Now saves motor speed/distance settings. Added time delay in motor direction reversely to prevent over drawing power from battery pack. 539 | 540 | http://download.dynamicperception.com/dpwu/mx3/1.05.hex 541 | 542 | 543 | 544 | 545 | 546 | 1.04 547 | 548 | Fixed flicker in VFD screen. Fix camera exposure time so it's updated in the interval time. 549 | 550 | http://download.dynamicperception.com/dpwu/mx3/1.04.hex 551 | 552 | 553 | 554 | 555 | 556 | 1.03 557 | 558 | Fixed Ramping Bug. Changed how cold weather mod works. 559 | 560 | http://download.dynamicperception.com/dpwu/mx3/1.03.hex 561 | 562 | 563 | 564 | 565 | 566 | 1.02 567 | 568 | Save States Added. 569 | 570 | http://download.dynamicperception.com/dpwu/mx3/1.02.hex 571 | 572 | 573 | 574 | 575 | 576 | 1.01 577 | 578 | SMS Bug Fix. 579 | 580 | http://download.dynamicperception.com/dpwu/mx3/1.01.hex 581 | 582 | 583 | 584 | 585 | 586 | 1.0 587 | 588 | First Production Release 589 | 590 | http://download.dynamicperception.com/dpwu/mx3/1.0.hex 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | --------------------------------------------------------------------------------