Skip to content

Commit

Permalink
Merge pull request #338 from aabadie/swarmit_demo
Browse files Browse the repository at this point in the history
swarmit: add sample application compatible with swarmit
  • Loading branch information
aabadie authored Nov 14, 2024
2 parents 1e19318 + 279b400 commit b20fd77
Show file tree
Hide file tree
Showing 18 changed files with 469 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ BUILD_CONFIG ?= Debug
BUILD_TARGET ?= dotbot-v1
PROJECT_FILE ?= $(BUILD_TARGET).emProject
BOOTLOADER ?= bootloader
SWARMIT_APPS ?=

ifeq (nrf5340dk-app,$(BUILD_TARGET))
PROJECTS ?= \
Expand Down Expand Up @@ -95,6 +96,7 @@ endif
ifneq (,$(filter dotbot-v2,$(BUILD_TARGET)))
PROJECTS := $(filter-out 03app_dotbot_gateway 03app_dotbot_gateway_lr 03app_sailbot 03app_xgo 03app_nrf5340_net 03app_freebot 03app_lh2_mini_mote%,$(PROJECTS))
ARTIFACT_PROJECTS := 03app_dotbot
SWARMIT_APPS := $(addprefix swarmit_, motors move rgbled timer)
endif

# remove incompatible apps (nrf5340, sailbot, gateway, dotbot) for lh2-mini-mote builds
Expand Down Expand Up @@ -149,7 +151,7 @@ ARTIFACTS = $(ARTIFACT_ELF) $(ARTIFACT_HEX)

.PHONY: $(PROJECTS) $(ARTIFACT_PROJECTS) artifacts docker docker-release format check-format

all: $(PROJECTS) $(OTAP_APPS) $(BOOTLOADER)
all: $(PROJECTS) $(OTAP_APPS) $(BOOTLOADER) $(SWARMIT_APPS)

$(PROJECTS):
@echo "\e[1mBuilding project $@\e[0m"
Expand All @@ -166,6 +168,11 @@ $(BOOTLOADER):
"$(SEGGER_DIR)/bin/emBuild" otap/$(BUILD_TARGET)-bootloader.emProject -project $@ -config Release $(PACKAGES_DIR_OPT) -rebuild -verbose
@echo "\e[1mDone\e[0m\n"

$(SWARMIT_APPS):
@echo "\e[1mBuilding $@ application\e[0m"
"$(SEGGER_DIR)/bin/emBuild" swarmit/swarmit.emProject -project $@ -config $(BUILD_CONFIG) $(PACKAGES_DIR_OPT) -rebuild -verbose
@echo "\e[1mDone\e[0m\n"

list-projects:
@echo "\e[1mAvailable projects:\e[0m"
@echo $(PROJECTS) | tr ' ' '\n'
Expand Down
1 change: 1 addition & 0 deletions doc/sphinx/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ applications
examples
otap
upgate
swarmit
api
```

Expand Down
4 changes: 4 additions & 0 deletions doc/sphinx/swarmit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```{include} ../../swarmit/README.md
:relative-images:
:relative-docs: ../
```
2 changes: 1 addition & 1 deletion nRF/System/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void reset_handler(void) {
_zero(&__bss_start__, &__bss_end__);
_zero(&__tbss_start__, &__tbss_end__);

#if defined(NRF5340_XXAA) && defined(NRF_APPLICATION)
#if defined(NRF5340_XXAA) && defined(NRF_APPLICATION) && !defined(USE_SWARMIT)
extern uint32_t __shared_data_start__;
extern uint32_t __shared_data_end__;
_zero(&__shared_data_start__, &__shared_data_end__);
Expand Down
9 changes: 9 additions & 0 deletions swarmit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SwarmIT samples

[SwarmIT](https://github.com/dotbots/swarmit) provides a lightweight
infrastructure to turn a swarm of robots in a testbed.

3 sample applications, compatible with SwarmIT, are provided to show how to
adapt DotBot-firmware code.
The sample applications are only compatible with the DotBot-v2 target, the only
robot powered by an nRF53 microcontroller, which is a requirement of SwarmIT.
Binary file added swarmit/cmse_implib.a
Binary file not shown.
1 change: 1 addition & 0 deletions swarmit/motors/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Motors board support package usage example
64 changes: 64 additions & 0 deletions swarmit/motors/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @file
* @defgroup swarmit_motors Motors application on top of SwarmIT
* @ingroup swarmit
* @brief This application controls the motors of the robot
*
* @author Alexandre Abadie <[email protected]>
* @copyright Inria, 2024
*/

#include <nrf.h>
#include <stdio.h>
#include <stdlib.h>

#include "board.h"
#include "motors.h"
#include "timer.h"

//=========================== swarmit ==========================================

void reload_wdt0(void);

//=========================== defines ==========================================

#define TIMER_DEV (0)

//=========================== main =============================================

int main(void) {

// Turn ON the DotBot board regulator
db_board_init();

// Initialize the timer
db_timer_init(TIMER_DEV);

db_timer_init(1);
db_timer_set_periodic_ms(1, 0, 500, &reload_wdt0);

// Configure Motors
db_motors_init();

while (1) {
// Move forward
for (uint8_t speed = 50; speed < 80; speed++) {
db_motors_set_speed(speed, speed);
db_timer_delay_ms(TIMER_DEV, 30);
}

// Move backward
for (uint8_t speed = 50; speed < 80; speed++) {
db_motors_set_speed(speed * -1, speed * -1);
db_timer_delay_ms(TIMER_DEV, 30);
}

// Spin
db_motors_set_speed(-70, 70);
db_timer_delay_ms(TIMER_DEV, 500);

// Spin back
db_motors_set_speed(70, -70);
db_timer_delay_ms(TIMER_DEV, 500);
}
}
1 change: 1 addition & 0 deletions swarmit/move/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# High-level move controls for the DotBot
46 changes: 46 additions & 0 deletions swarmit/move/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @file
* @defgroup swarmit_move Move application on top of SwarmIT
* @ingroup swarmit
* @brief This application uses the move API to make the robot move
*
* @author Alexandre Abadie <[email protected]>
* @copyright Inria, 2024
*/

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <nrf.h>
#include "move.h"
#include "timer.h"
#include "gpio.h"
#include "board_config.h"

//=========================== swarmit ==========================================

void reload_wdt0(void);

//=========================== main =============================================

int main(void) {
db_timer_init(1);
db_timer_set_periodic_ms(1, 0, 500, &reload_wdt0);

db_gpio_init(&db_led1, DB_GPIO_OUT);

db_move_init();
db_move_straight(200, 60);
db_move_rotate(90, 60);
db_move_straight(200, 60);
db_move_rotate(90, 60);
db_move_straight(200, 60);
db_move_rotate(90, 60);
db_move_straight(200, 60);
db_move_rotate(90, 60);

while (1) {
db_gpio_toggle(&db_led1);
db_timer_delay_ms(1, 250);
}
}
8 changes: 8 additions & 0 deletions swarmit/nRF5340_xxAA_Application_MemoryMap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE Board_Memory_Definition_File>
<root name="nRF5340_xxAA_Application">
<MemorySegment name="FLASH1" start="0x00004000" size="0x00100000 - 0x4000" access="ReadOnly" />
<MemorySegment name="NSC_FLASH" start="0x00004000 - 0x100" size="0x00000100" access="ReadOnly" />
<MemorySegment name="EXT_FLASH1" start="0x10000000" size="0x08000000" access="ReadOnly" />
<MemorySegment name="RAM1" start="0x20020000" size="0x00020000" access="Read/Write" />
<MemorySegment name="RAM2" start="0x20040000" size="0x0003F000" access="Read/Write" />
</root>
36 changes: 36 additions & 0 deletions swarmit/nRF5340_xxAA_Application_flash_placement.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE Linker_Placement_File>
<Root name="Flash Section Placement">
<MemorySegment name="$(FLASH_NAME:FLASH);FLASH1">
<ProgramSection alignment="0x100" load="Yes" name=".vectors" start="$(FLASH_START:)" />
<ProgramSection alignment="4" load="Yes" name=".init" />
<ProgramSection alignment="4" load="Yes" name=".init_rodata" />
<ProgramSection alignment="4" load="Yes" name=".text" />
<ProgramSection alignment="4" load="Yes" name=".dtors" />
<ProgramSection alignment="4" load="Yes" name=".ctors" />
<ProgramSection alignment="4" load="Yes" name=".rodata" />
<ProgramSection alignment="4" load="Yes" name=".ARM.exidx" address_symbol="__exidx_start" end_symbol="__exidx_end" />
<ProgramSection alignment="4" load="Yes" runin=".fast_run" name=".fast" />
<ProgramSection alignment="4" load="Yes" runin=".data_run" name=".data" />
<ProgramSection alignment="4" load="Yes" runin=".tdata_run" name=".tdata" />
</MemorySegment>
<MemorySegment name="$(RAM_NAME:RAM);SRAM;RAM1">
<ProgramSection alignment="4" load="No" name=".fast_run" />
<ProgramSection alignment="4" load="No" name=".data_run" />
<ProgramSection alignment="4" load="No" name=".bss" />
<ProgramSection alignment="4" load="No" name=".tbss" />
<ProgramSection alignment="4" load="No" name=".tdata_run" />
<ProgramSection alignment="4" load="No" name=".non_init" />
<ProgramSection alignment="8" size="__HEAPSIZE__" load="No" name=".heap" />
<ProgramSection alignment="8" size="__STACKSIZE__" load="No" place_from_segment_end="Yes" name=".stack" />
<ProgramSection alignment="8" size="__STACKSIZE_PROCESS__" load="No" name=".stack_process" />
</MemorySegment>
<MemorySegment name="$(FLASH2_NAME:FLASH2)">
<ProgramSection alignment="4" load="Yes" name=".text2" />
<ProgramSection alignment="4" load="Yes" name=".rodata2" />
<ProgramSection alignment="4" load="Yes" runin=".data2_run" name=".data2" />
</MemorySegment>
<MemorySegment name="$(RAM2_NAME:RAM2)">
<ProgramSection alignment="4" load="No" name=".data2_run" />
<ProgramSection alignment="4" load="No" name=".bss2" />
</MemorySegment>
</Root>
4 changes: 4 additions & 0 deletions swarmit/projects.dox
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* @defgroup swarmit SwarmIT sample applications
* @brief Sample applications showcasing SwarmIT usage with DotBot-firmware
*/
4 changes: 4 additions & 0 deletions swarmit/rgbled/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# RGB LED sample

Loading this app onto the DotBot board will change the RGB LED color every 2
seconds in a loop.
64 changes: 64 additions & 0 deletions swarmit/rgbled/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @file
* @defgroup swarmit_rgbled RGBLed application on top of SwarmIT
* @ingroup swarmit
* @brief This application uses the RGB LED API
*
* @author Alexandre Abadie <[email protected]>
* @copyright Inria, 2024
*/

#include <nrf.h>
#include <stdio.h>
#include <stdlib.h>
#include "board.h"
#include "rgbled_pwm.h"
#include "timer.h"
#include "board_config.h"

//=========================== swarmit ==========================================

void reload_wdt0(void);

//=========================== defines ==========================================

#define TIMER_DEV (0)
#define RGB_LED_DELAY_MS (200U)

//=========================== variables ========================================

static const db_rgbled_pwm_conf_t rgbled_pwm_conf = {
.pwm = 1,
.pins = {
{ .port = DB_RGB_LED_PWM_RED_PORT, .pin = DB_RGB_LED_PWM_RED_PIN },
{ .port = DB_RGB_LED_PWM_GREEN_PORT, .pin = DB_RGB_LED_PWM_GREEN_PIN },
{ .port = DB_RGB_LED_PWM_BLUE_PORT, .pin = DB_RGB_LED_PWM_BLUE_PIN },
}
};

//=========================== main =============================================

int main(void) {
db_board_init();

db_timer_init(TIMER_DEV);
db_timer_set_periodic_ms(TIMER_DEV, 0, 500, &reload_wdt0);

db_rgbled_pwm_init(&rgbled_pwm_conf);

/* Change RGB colors in a loop */
while (1) {
db_rgbled_pwm_set_color(255, 0, 0);
db_timer_delay_ms(TIMER_DEV, RGB_LED_DELAY_MS);
db_rgbled_pwm_set_color(0, 255, 0);
db_timer_delay_ms(TIMER_DEV, RGB_LED_DELAY_MS);
db_rgbled_pwm_set_color(0, 0, 255);
db_timer_delay_ms(TIMER_DEV, RGB_LED_DELAY_MS);
db_rgbled_pwm_set_color(255, 255, 0);
db_timer_delay_ms(TIMER_DEV, RGB_LED_DELAY_MS);
db_rgbled_pwm_set_color(0, 255, 255);
db_timer_delay_ms(TIMER_DEV, RGB_LED_DELAY_MS);
db_rgbled_pwm_set_color(255, 0, 255);
db_timer_delay_ms(TIMER_DEV, RGB_LED_DELAY_MS);
}
}
Loading

0 comments on commit b20fd77

Please sign in to comment.