Commit dc5b7b5e authored by Jake Read's avatar Jake Read
Browse files

events have legs

parents
jake/
**.elf
**.hex
**.bin
**.lss
**.map
**.srec
**.o
**.d
**.DS_Store
**.b#*
**.s#*
**/ASF/
embedded/atsams70-usbcdc/
embedded/usb-adafruit/
embedded/usb-xplained/
js/node_modules/
node_modules/
sim/js_code.txt
sim/TinyNets/nbproject/
# ATKAPI App Building
http://designmodo.github.io/Flat-UI/
http://workshop.chromeexperiments.com/examples/gui/#1--Basic-Usage
bootstrap, numeric.js ...
http://backbonejs.org/#Events
## Network Motion Control Scheme
Motors eat trapezoid packets, acknowledge when complete with int32_t of steps taken, updates window transmission and current position tracker.
Path planner has:
- complete path in memory
- current position
- path ptrs:
- plan end (last segment accel planned for, zero exit speed)
- current segment (last segment to go out network buffer)
- path planning is an app that uses atkapi
- atkapi: create objs of hardware nodes,
- .settings
.reset()
.disable()
... etc
- for replies, these obj's should fire events that can be listened to
automatakit
automatickit
# Ambitions for this page
- landing page for all users, consider FAB14 workshop landing here
- is machine / robot control for fungible machines
- show video examples Reich, MoControl
- explain scheme, idea, statelessness and event-basedness
- practicum
- how to mkterminal, what is
- how to atk api javascript
- explain example application entry point
- explain example C code
# Machine Kit API
XX Is a collection of hardware, firmware and software that lets you build machines in the same way we build software: quickly, with great joy, and with rapid reconfiguration of resources.
With XX, all of the motors, sensors, and end effectors in a machine are connected via a low-latency network that we call [APA](link). An API allows us to interface with this network to build applications for machine control.
```JavaScript
Stepper.trapezoid(entry,steps,rate,exit);
Stepper.onPacket(packet){
// on return packet
}
DCRotary.setPos(pos);
DCRotary.onPacket(packet){
//
}
// all have
Endpoint.sendPacket(packet);
Endpoint.onPacket(packet){
// returning
}
```
Entry points to the network are through the [mksocketserver](link) and [mkterminal](link) interfaces. These open hardware ports on a host computer to send and receive messages across the network.
Endpoints are hardware objects that receive control commands, and execute them faithfully: move motors, read sensors, heat things, control positions and currents, etc.
## APA Networking
- clean nomenclature: 'routers' are 'nodes' and can be just-routers or endpoints, etc, anything that lives on the network is a node
### The Packet
*Asynchronous Packet Automata* is a networking scheme from Neil Gershenfeld, wherein packets traverse a network not based on destination addresses, but on designated routes. In Technical Networking Language, is is a source-routed port-forwarding scheme, which means that routing is done at the source of the packet, and upon arriving at a position in the network, packets are forwarded along another port, or consumed at that position, based on the route contained in the packet. As the packet traverses the network, pieces of the route are 'consumed' and replaced with a reversed route, such that the destination knows how to return the packet.
The structure of a packet is typically broken into bytes (8-bit long 'words') and is structured like this:
![apa-packet](/images/apa-packet-structure.png)
The 1st byte of any packet denotes the length of the complete packet, in bytes, and is used to parse packets arriving at nodes. For example, when a node starts receiving a packet, it takes the first byte arriving to be the length, and counts bytes until the end is reached, when it can then act on the packet.
### Routing
Bytes in the route-header section of the packet designate the order of ports the packet should be forwarded on. When the packet arrives at a new network node, the node shifts-out the last port, and adds to the tail of the route-header the port that the packet arrived on, effectively adding return information to the route. The 'pointer' (we designate the byte representing 254, or ^ diagramatically), denotes the packet's current position in the route.
We can see an example packet traversal here:
![apa-packet-traverse](/images/apa-packet-traverse.png)
![apa-packet-route-shift](/images/apa-packet-shift.png)
Because of the route-header shifting, the 1st byte in the route-header always denotes the port number which the packet should leave the current node on. If the 1st byte in the route-header is the pointer (^ or 254) the packet is at its destination and should be consumed by that node. At this point, the tail of the packet-header contains a route which, when reversed, forms a route back to it's original source.
![apa-packet-reply](/images/apa-packet-reply.png)
### The Physical Layer
APA does not designate a particular Physical Layer (in Networking Nomenclature, referred to as a 'PHY', or Layer 2). AutomataKit uses a microcontroller's UART peripheral for the PHY layer, but we are expanding to use FPGAs and a per-bit token-passing scheme, as well as exploring wireless links.
### Hardware Implementation
The network nodes implemented in AutomataKit use a UART Physical Layer. This means that network packets arrive on a per-byte basis, and are parsed into packets in the microcontroller's C code (firmware).
... etc
## Endpoints
Endpoints are hardware...
Global API
**127** test, turns on a light and returns the packet
**128** reset, resets the board
**129** setpos,
**130** getpos,
**131** trapezoid,
### MKRouter
### MKStepper17
### MKStepper23
### MKBLDCDriver
### MKBreadBoardBoard
### MKSmallRotary
## Applications
- example applications do:
- mocontrol acceleration
- dynamic control
- feedback?
## Firmware
To build, program and debug firmware, I use Atmel Studio 7. Code for all of the endpoints is kept in their respective repositories, under the embedded/ directory.
While the code is kept in the repositories, supporting libraries and build tools are not - we need Atmel Studio to do this for us.
In Atmel Studio, start a new project, select 'GCC Executable Project' and set the location to be the sub-directory where the .c and .h files are kept.
![atsuo-1](/images/atstudio-01.png)
On the next page, select the Device to be an ATSAMD51J19 (or J18) - this is the microcontroller most of the Machine Kit endpoints run. A J19 is the 512kB version, the J18 is the 256kB version.
![atsuo-2](/images/atstudio-02.png)
Now Atmel Studio should be set up, but we need to have it include the existing .c and .h files.
In the Atmel Studio 'Solution Explorer' (might not be open, go to View -> Solution Explorer), right-click on the Solution (mkembedded-example in this case) and do Add -> Existing Item
![atsuo-3](/images/atstudio-03.png)
Now select all of the .c and .h files from the example code.
![atsuo-4](/images/atstudio-04.png)
Your Atmel Studio environment and project embedded director should look something like this:
![atsuo-5](/images/atstudio-05.png)
Now we should be ready to build the example:
![atsuo-6](/images/atstudio-06.png)
To load a program onto the device, connect the programmer (in this case, I'm using an Atmel ICE) and do Ctrl + Alt + F5, or hit the little 'play' button underneath the 'window' menu item.
If you get an error saying you don't have a tool connected, hit OK and select the Atmel-ICE from the menu that appears. Otherwise, to set up a programming tool in Atmel Studio go to 'Tools -> Device Programming' or right-click on the solution and open the properties. From there you can select a tool in the 'Tool' tab on the left.
# Global Notes
## W/R/T ATSAMD51
/*
Jake Read 2018 06 09
Socket Client
of ATKAPI
sends and receives data from socket server, running at machine head
*/
\ No newline at end of file
<!--
Jake Read 2018 06 09
Terminal App
of ATKAPI
-->
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "UTF-8">
<title>ATK API Terminal</title>
</head>
<body>
<div id="terminalWindow">
<p>Yonder Terminal</p>
<input id='terminalInput' type='text' size=64>
<div id='terminalOutput'></div>
</div>
<script type="text/javascript" src="/js/base.js"></script>
<script type="text/javascript" src="/app/terminal/main.js"></script>
</body>
</html>
\ No newline at end of file
/*
Jake Read 2018 06 09
Test App
of ATKAPI
*/
// two objects, each with an output function and an input function
//var _controller = NewController()
var logOne = NewLogger()
var logTwo = NewLogger()
// using controller
//_controller.on(logOne.newMessage, logTwo.log)
// oshiiii we don't need the controller?
// or attaching event by calling itself
logOne.newMessage.attach(logTwo.log)
logOne.log('longOne.logOnce')
logOne.newMessage.remove(logTwo.log)
logOne.log('logOne.logTwice')
logOne.newMessage.remove(logTwo.log)
logOne.log('logOne.logThrice')
/*
Jake Read 2018 06 09
Socket Server
of ATKAPI
runs at machine head, listens to atkSocketClient and dishes / receives messages
*/
\ No newline at end of file
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
SHELL := cmd.exe
RM := rm -rf
USER_OBJS :=
LIBS :=
PROJ :=
O_SRCS :=
C_SRCS :=
S_SRCS :=
S_UPPER_SRCS :=
OBJ_SRCS :=
ASM_SRCS :=
PREPROCESSING_SRCS :=
OBJS :=
OBJS_AS_ARGS :=
C_DEPS :=
C_DEPS_AS_ARGS :=
EXECUTABLES :=
OUTPUT_FILE_PATH :=
OUTPUT_FILE_PATH_AS_ARGS :=
AVR_APP_PATH :=$$$AVR_APP_PATH$$$
QUOTE := "
ADDITIONAL_DEPENDENCIES:=
OUTPUT_FILE_DEP:=
LIB_DEP:=
LINKER_SCRIPT_DEP:=
# Every subdirectory with source files must be described here
SUBDIRS := \
../Device_Startup/
# Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \
../apahandler.c \
../apaport.c \
../Device_Startup/startup_samd51.c \
../Device_Startup/system_samd51.c \
../main.c \
../pin.c \
../ringbuffer.c \
../uartport.c
PREPROCESSING_SRCS +=
ASM_SRCS +=
OBJS += \
apahandler.o \
apaport.o \
Device_Startup/startup_samd51.o \
Device_Startup/system_samd51.o \
main.o \
pin.o \
ringbuffer.o \
uartport.o
OBJS_AS_ARGS += \
apahandler.o \
apaport.o \
Device_Startup/startup_samd51.o \
Device_Startup/system_samd51.o \
main.o \
pin.o \
ringbuffer.o \
uartport.o
C_DEPS += \
apahandler.d \
apaport.d \
Device_Startup/startup_samd51.d \
Device_Startup/system_samd51.d \
main.d \
pin.d \
ringbuffer.d \
uartport.d
C_DEPS_AS_ARGS += \
apahandler.d \
apaport.d \
Device_Startup/startup_samd51.d \
Device_Startup/system_samd51.d \
main.d \
pin.d \
ringbuffer.d \
uartport.d
OUTPUT_FILE_PATH +=mkembedded-example.elf
OUTPUT_FILE_PATH_AS_ARGS +=mkembedded-example.elf
ADDITIONAL_DEPENDENCIES:=
OUTPUT_FILE_DEP:= ./makedep.mk
LIB_DEP+=
LINKER_SCRIPT_DEP+= \
../Device_Startup/samd51j18a_flash.ld \
../Device_Startup/samd51j18a_sram.ld
# AVR32/GNU C Compiler
./%.o: .././%.c
@echo Building file: $<
@echo Invoking: ARM/GNU C Compiler : 6.3.1
$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-gcc.exe$(QUOTE) -x c -mthumb -D__SAMD51J18A__ -DDEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\arm\CMSIS\5.0.1\CMSIS\Include" -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\SAMD51_DFP\1.0.70\include" -O1 -ffunction-sections -mlong-calls -g3 -Wall -mcpu=cortex-m4 -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<"
@echo Finished building: $<
Device_Startup/%.o: ../Device_Startup/%.c
@echo Building file: $<
@echo Invoking: ARM/GNU C Compiler : 6.3.1
$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-gcc.exe$(QUOTE) -x c -mthumb -D__SAMD51J18A__ -DDEBUG -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\arm\CMSIS\5.0.1\CMSIS\Include" -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\SAMD51_DFP\1.0.70\include" -O1 -ffunction-sections -mlong-calls -g3 -Wall -mcpu=cortex-m4 -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<"
@echo Finished building: $<
# AVR32/GNU Preprocessing Assembler
# AVR32/GNU Assembler
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif
# Add inputs and outputs from these tool invocations to the build variables
# All Target
all: $(OUTPUT_FILE_PATH) $(ADDITIONAL_DEPENDENCIES)
$(OUTPUT_FILE_PATH): $(OBJS) $(USER_OBJS) $(OUTPUT_FILE_DEP) $(LIB_DEP) $(LINKER_SCRIPT_DEP)
@echo Building target: $@
@echo Invoking: ARM/GNU Linker : 6.3.1
$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-gcc.exe$(QUOTE) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS) -mthumb -Wl,-Map="mkembedded-example.map" -Wl,--start-group -lm -Wl,--end-group -L"..\\Device_Startup" -Wl,--gc-sections -mcpu=cortex-m4 -Tsamd51j18a_flash.ld
@echo Finished building target: $@
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-objcopy.exe" -O binary "mkembedded-example.elf" "mkembedded-example.bin"
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature "mkembedded-example.elf" "mkembedded-example.hex"
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O binary "mkembedded-example.elf" "mkembedded-example.eep" || exit 0
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-objdump.exe" -h -S "mkembedded-example.elf" > "mkembedded-example.lss"
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature "mkembedded-example.elf" "mkembedded-example.srec"
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\arm\arm-gnu-toolchain\bin\arm-none-eabi-size.exe" "mkembedded-example.elf"
# Other Targets
clean:
-$(RM) $(OBJS_AS_ARGS) $(EXECUTABLES)
-$(RM) $(C_DEPS_AS_ARGS)
rm -rf "mkembedded-example.elf" "mkembedded-example.a" "mkembedded-example.hex" "mkembedded-example.bin" "mkembedded-example.lss" "mkembedded-example.eep" "mkembedded-example.map" "mkembedded-example.srec"
\ No newline at end of file
################################################################################
# Automatically-generated file. Do not edit or delete the file
################################################################################
apahandler.c
apaport.c
Device_Startup\startup_samd51.c
Device_Startup\system_samd51.c
main.c
pin.c
ringbuffer.c
uartport.c
/**
* \file
*
* \brief Linker script for running in internal FLASH on the SAMD51J18A
*
* Copyright (c) 2017 Microchip Technology Inc.
*
* \asf_license_start
*
* \page License
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the Licence at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* \asf_license_stop
*
*/
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
SEARCH_DIR(.)
/* Memory Spaces Definitions */
MEMORY
{
rom (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00020000
bkupram (rwx) : ORIGIN = 0x47000000, LENGTH = 0x00002000
qspi (rwx) : ORIGIN = 0x04000000, LENGTH = 0x01000000
}
/* The stack size used by the application. NOTE: you need to adjust according to your application. */
STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : DEFINED(__stack_size__) ? __stack_size__ : 0x8000;
/* Section Definitions */
SECTIONS
{
.text :
{
. = ALIGN(4);
_sfixed = .;
KEEP(*(.vectors .vectors.*))
*(.text .text.* .gnu.linkonce.t.*)
*(.glue_7t) *(.glue_7)
*(.rodata .rodata* .gnu.linkonce.r.*)
*(.ARM.extab* .gnu.linkonce.armextab.*)
/* Support C constructors, and C destructors in both user code
and the C library. This also provides support for C++ code. */
. = ALIGN(4);
KEEP(*(.init))
. = ALIGN(4);
__preinit_array_start = .;
KEEP (*(.preinit_array))
__preinit_array_end = .;
. = ALIGN(4);
__init_array_start = .;
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
__init_array_end = .;
. = ALIGN(4);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*crtend.o(.ctors))
. = ALIGN(4);
KEEP(*(.fini))
. = ALIGN(4);
__fini_array_start = .;
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
__fini_array_end = .;
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*crtend.o(.dtors))
. = ALIGN(4);
_efixed = .; /* End of text section */
} > rom
/* .ARM.exidx is sorted, so has to go in its own output section. */
PROVIDE_HIDDEN (__exidx_start = .);
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > rom
PROVIDE_HIDDEN (__exidx_end = .);
. = ALIGN(4);
_etext = .;
.relocate : AT (_etext)
{
. = ALIGN(4);
_srelocate = .;
*(.ramfunc .ramfunc.*);
*(.data .data.*);
. = ALIGN(4);
_erelocate = .;
} > ram