Skip to content

Commit

Permalink
v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielburnworth committed Jun 1, 2022
1 parent 566c853 commit 6801924
Show file tree
Hide file tree
Showing 33 changed files with 277 additions and 637 deletions.
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,17 @@ PREFIX = $(MIX_APP_PATH)/priv
FIRMWARE_SRC := $(wildcard firmware_src/src/*.cpp)
FIRMWARE_SRC += $(wildcard firmware_src/include/*.h)

.PHONY: all clean burn_encoder_tracker
.PHONY: all clean

all: $(PREFIX) $(PREFIX)/firmware.hex

clean:
platformio run -d firmware_src -t clean
$(RM) $(PREFIX)/firmware.hex
$(RM) $(PREFIX)/firmware.hex

$(PREFIX):
mkdir -p $(PREFIX)

$(PREFIX)/firmware.hex: $(FIRMWARE_SRC)
PLATFORMIO_BUILD_FLAGS="-DMIX_TARGET_$(MIX_TARGET) -DMIX_TARGET=\"$(MIX_TARGET)\"" platformio run -d firmware_src/
cp firmware_src/.pio/build/megaatmega2560/firmware.hex $(PREFIX)/firmware.hex

burn_encoder_tracker:
st-flash write firmware_src/priv/EncoderTracker\(12352db\ mode0\).bin 0x8000000
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
# POST
# FarmBot factory test firmware

Tests electronics box LEDs,
Farmduino peripherals using load sensors (including rotary tool on Genesis),
and motors using encoders.

Press the red E-STOP button to proceed through tests.

All LEDs flashing indicates error.

```
MIX_TARGET=rpi4 mix deps.get
MIX_TARGET=rpi4 mix firmware.image factory_test_genesis_v1.6_pi4.img
MIX_TARGET=rpi02w mix deps.get
MIX_TARGET=rpi02w mix firmware.image factory_test_express_v1.1_pi02w.img
```

[Nerves docs](https://hexdocs.pm/nerves/getting-started.html)
11 changes: 5 additions & 6 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
# and its dependencies with the aid of the Config module.
#
# This configuration file is loaded before any dependency and
# is restricted to this project.
use Mix.Config
import Config

config :post, target: Mix.target()

Expand All @@ -17,7 +17,7 @@ config :nerves, :firmware, rootfs_overlay: "rootfs_overlay"
# involved with firmware updates.

config :shoehorn,
init: [:nerves_runtime, :vintage_net],
init: [:nerves_runtime],
app: Mix.Project.config()[:app]

# Use Ringlogger as the logger backend and remove :console.
Expand All @@ -32,10 +32,9 @@ config :post, POST.PlatformSupervisor, children: []
if Mix.target() != :host do
import_config "target.exs"
else
import_config "profiles/FARMDUINO_K15.ex"
# import_config "profiles/EXPRESS_K10.ex"
import_config "profiles/FARMDUINO_K16.ex"
# import_config "profiles/EXPRESS_K11.ex"
# config :post, POST.Comms, device: "ttyUSB0"
config :post, POST.Comms.FlashFirmware, reset: POST.Comms.FlashFirmware.NullReset
config :post, POST.ButtonSupervisor, button: POST.NullButton
config :post, POST.LEDSupervisor, led: POST.NullLED
end
17 changes: 0 additions & 17 deletions config/profiles/EXPRESS_K10.ex

This file was deleted.

15 changes: 15 additions & 0 deletions config/profiles/EXPRESS_K11.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Config
IO.puts("using EXPRESS_K11 profile")

config :post, POST.Comms, device: "ttyUSB0"

config :post, POST.ButtonSupervisor, button: POST.GPIOButton

config :post, POST.ButtonPopulator, buttons: [16, 22]

config :post, POST.LEDSupervisor, led: POST.GPIOLED

config :post, POST.LEDPopulator, leds: [17, 23, 24, 25]

config :post, POST.TestSuite, peripherals: [0, 1, 2]
config :post, POST.TestSuite, motors: [0, 1, 2, 3]
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use Mix.Config
IO.puts("using FARMDUINO_K15 profile")
import Config
IO.puts("using FARMDUINO_K16 profile")

config :post, POST.Comms, device: "ttyACM0"

config :post, POST.Comms.FlashFirmware, reset: POST.Comms.FlashFirmware.NullReset

config :post, POST.ButtonSupervisor, button: POST.GPIOButton

config :post, POST.ButtonPopulator, buttons: [16, 22, 26, 5, 20]
Expand All @@ -14,5 +12,5 @@ config :post, POST.LEDSupervisor, led: POST.GPIOLED
config :post, POST.LEDPopulator, leds: [17, 23, 27, 06, 21, 24, 25, 12, 13]

config :post, POST.TestSuite,
peripherals: [0, 1, 2, 3, 4],
peripherals: [0, 1, 2, 3, 4, 5, 6],
motors: [0, 1, 2, 3, 4]
4 changes: 1 addition & 3 deletions config/profiles/NULL.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use Mix.Config
import Config
IO.puts("using NULL profile")

config :post, POST.Comms, device: nil

config :post, POST.Comms.FlashFirmware, reset: POST.Comms.FlashFirmware.NullReset

config :post, POST.ButtonSupervisor, button: POST.NullButton
config :post, POST.ButtonPopulator, buttons: [16]

Expand Down
9 changes: 0 additions & 9 deletions config/rpi.exs

This file was deleted.

4 changes: 4 additions & 0 deletions config/rpi02w.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Config

config :post, POST.PlatformSupervisor, children: []
import_config "profiles/EXPRESS_K11.ex"
4 changes: 0 additions & 4 deletions config/rpi3.exs

This file was deleted.

4 changes: 4 additions & 0 deletions config/rpi4.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Config

config :post, POST.PlatformSupervisor, children: []
import_config "profiles/FARMDUINO_K16.ex"
88 changes: 1 addition & 87 deletions config/target.exs
Original file line number Diff line number Diff line change
@@ -1,93 +1,7 @@
use Mix.Config
import Config

# Authorize the device to receive firmware using your public key.
# See https://hexdocs.pm/nerves_firmware_ssh/readme.html for more information
# on configuring nerves_firmware_ssh.
config :logger, backends: [RingLogger]

keys =
[
Path.join([System.user_home!(), ".ssh", "id_rsa.pub"]),
Path.join([System.user_home!(), ".ssh", "id_ecdsa.pub"]),
Path.join([System.user_home!(), ".ssh", "id_ed25519.pub"])
]
|> Enum.filter(&File.exists?/1)

if keys == [],
do:
Mix.raise("""
No SSH public keys found in ~/.ssh. An ssh authorized key is needed to
log into the Nerves device and update firmware on it using ssh.
See your project's config.exs for this error message.
""")

config :nerves_firmware_ssh,
authorized_keys: Enum.map(keys, &File.read!/1)

config :mdns_lite,
# The `host` key specifies what hostnames mdns_lite advertises. `:hostname`
# advertises the device's hostname.local. For the official Nerves systems, this
# is "nerves-<4 digit serial#>.local". mdns_lite also advertises
# "nerves.local" for convenience. If more than one Nerves device is on the
# network, delete "nerves" from the list.

host: [:hostname],
ttl: 120,

# Advertise the following services over mDNS.
services: [
%{
name: "SSH Remote Login Protocol",
protocol: "ssh",
transport: "tcp",
port: 22
},
%{
name: "Secure File Transfer Protocol over SSH",
protocol: "sftp-ssh",
transport: "tcp",
port: 22
},
%{
name: "Erlang Port Mapper Daemon",
protocol: "epmd",
transport: "tcp",
port: 4369
}
]

wifi =
if System.get_env("SSID") do
%{
ssid: System.get_env("SSID"),
psk: System.get_env("PSK"),
key_mgmt: :wpa_psk
}
else
%{}
end

config :vintage_net,
regulatory_domain: "US",
config: [
{"usb0", %{type: VintageNet.Technology.Gadget}},
{"eth0",
%{
type: VintageNet.Technology.Ethernet,
ipv4: %{
method: :dhcp
}
}},
{"wlan0",
%{
type: VintageNet.Technology.WiFi,
ipv4: %{
method: :dhcp
},
wifi: wifi
}}
]

# Import target specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
# Uncomment to use target specific configurations
Expand Down
24 changes: 12 additions & 12 deletions firmware_src/encoder_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#define ADC5 A2

//////////////// STM32 ////////////////
#define NSS_PIN 22
#define NSS_PIN 22
#define STM_RST_PIN 49

static const int spi_encoder_offset = 4;
Expand Down Expand Up @@ -118,7 +118,7 @@ void setup() {
delay(5);
digitalWrite(STM_RST_PIN, HIGH);
delay(20);

//reset all encoder
ResetEncoder();
delay(20);
Expand All @@ -127,8 +127,8 @@ void setup() {

RunTest();
}
void loop()

void loop()
{
}

Expand All @@ -140,7 +140,7 @@ void RunTest()
bool encoder2Error = false;
bool encoder3Error = false;
bool encoder4Error = false;

bool adc1Error = false;
bool adc2Error = false;
bool adc3Error = false;
Expand All @@ -163,7 +163,7 @@ void RunTest()
encoder2 = ReadEncoder(_X2);
encoder3 = ReadEncoder(_Y);
encoder4 = ReadEncoder(_Z);

Serial.print("X1 reading: ");
Serial.println(encoder1);
Serial.print("X2 reading: ");
Expand All @@ -172,7 +172,7 @@ void RunTest()
Serial.println(encoder3);
Serial.print("Z reading: ");
Serial.println(encoder4);

encoder1Error = encoder1 < encoderThreshold;
encoder2Error = encoder2 < encoderThreshold;
encoder3Error = encoder3 < encoderThreshold;
Expand All @@ -186,7 +186,7 @@ void RunTest()
digitalWrite(FET3,1);
digitalWrite(FET4,1);
digitalWrite(FET5,1);

//move motors backwards
SendPulse(num_pulse, reverse_val);

Expand All @@ -196,7 +196,7 @@ void RunTest()
adc3Error = analogRead(ADC3) > adcThreshold;
adc4Error = analogRead(ADC4) > adcThreshold;
adc5Error = analogRead(ADC5) > adcThreshold;

//turn off mosfets with OK readings
digitalWrite(FET1, !adc1Error);
digitalWrite(FET2, !adc2Error);
Expand Down Expand Up @@ -234,7 +234,7 @@ void ResetEncoder()
{
const byte reset_cmd = 0xF0;

SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE3));
digitalWrite(NSS_PIN,LOW);
delayMicroseconds(2);
SPI.transfer(reset_cmd);
Expand All @@ -251,7 +251,7 @@ long ReadEncoder(SpiEncoders encoder)
const int readSize = 4;
long encoderVal = 0;

SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE3));
digitalWrite(NSS_PIN,LOW);
delayMicroseconds(2);
SPI.transfer(read_cmd | (encoder << spi_encoder_offset) );
Expand All @@ -262,7 +262,7 @@ long ReadEncoder(SpiEncoders encoder)
encoderVal <<= 8;
encoderVal |= SPI.transfer(0x01);
}

digitalWrite(NSS_PIN,HIGH);
SPI.endTransaction();
delay(10);
Expand Down
Loading

0 comments on commit 6801924

Please sign in to comment.