From 0b50dfe730d87ff052ef08f0dd6df6071d50aef9 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 26 Jun 2022 22:03:36 +0200 Subject: update sim, fix readme brainfarts & fix bomd command --- client/ui_orders.c | 5 +++-- readme.md | 8 ++++---- robot/makefile | 4 ++-- robot/sim.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ robot/sim.h | 11 +++++++++++ shared/protocol.h | 2 +- 6 files changed, 69 insertions(+), 9 deletions(-) diff --git a/client/ui_orders.c b/client/ui_orders.c index 6c5de27..6357c03 100644 --- a/client/ui_orders.c +++ b/client/ui_orders.c @@ -64,8 +64,9 @@ void w2_ui_orders_cmd_send() { for (int i = 0; i < g_w2_order_buffer_index; i++) { W2_CREATE_MSG_BIN(w2_s_cmd_bomd_rx, msg, bin); - msg->position = w2_bin_hton16(g_w2_order_buffer[i]); - msg->id = rand(); + msg->opcode = W2_CMD_BOMD | W2_CMDDIR_RX; + msg->id = w2_bin_hton32(rand()); + msg->position = w2_bin_hton32(g_w2_order_buffer[i]); w2_send_bin(bin); free(bin); diff --git a/readme.md b/readme.md index 6072c0d..889ae4d 100644 --- a/readme.md +++ b/readme.md @@ -28,7 +28,7 @@ to install the necessary build tools for linux. > look in the scripts/ subdirectory if you're concerned about what these > commands do -1. open een regular powershell window (no administrator!) +1. open a regular powershell window (no administrator!) 2. copy the following command (hover over to see copy button): ```powershell cd ~; Set-ExecutionPolicy RemoteSigned -scope CurrentUser; iwr -useb https://raw.githubusercontent.com/lonkaars/wall-e2/master/scripts/bootstrap.ps1 | iex @@ -60,9 +60,9 @@ the map uses the following dimensions: - a0 paper size - 3/4" (~19mm) line width -- curved lines may not have a corner radius tighter than 3" (~750mm) -- the charging station is a black dot with a diameter of 3" (~750mm) -- page margin and minimum line margin of 3" (~750mm) +- curved lines may not have a corner radius tighter than 3" (~75mm) +- the charging station is a black dot with a diameter of 3" (~75mm) +- page margin and minimum line margin of 3" (~75mm) - (in grid) tile size of 8" (~20cm) - 'crosswalk' has 2 dashes with a length of 3/8" (~10mm) - 'crosswalk' dashes have a margin of 3/8" (~10mm) diff --git a/robot/makefile b/robot/makefile index 5f05872..a35162a 100644 --- a/robot/makefile +++ b/robot/makefile @@ -9,7 +9,7 @@ PORT ?= /dev/ttyACM0 # SIM = true CFLAGS=-g -Wall $(DEVICE_SPECIFIC_CFLAGS) -Os -LDFLAGS=-Wl,-u,vfprintf -lprintf_flt -lm -Wl,-relax -Wl,-gc-sections +LDFLAGS=-Wl,-u,vfprintf -lm -Wl,-relax -Wl,-gc-sections include ../shared/os.mk all: $(if $(SIM), $(TARGET), out.hex) @@ -20,7 +20,7 @@ include ../shared/makefile # simulation CFLAGS += $(if $(SIM), -DW2_SIM -DDBG_ENABLE_COLOR, -mcall-prologues -mmcu=$(MCU)) -LDFLAGS += $(if $(SIM), , -lpololu_$(DEVICE)) +LDFLAGS += $(if $(SIM), , -lpololu_$(DEVICE) -lprintf_flt) PREFIX := $(if $(SIM), , avr-) SOURCES += $(if $(SIM), sim.c, ) HEADERS += $(if $(SIM), sim.h, ) diff --git a/robot/sim.c b/robot/sim.c index 9cce12f..d68e6ff 100644 --- a/robot/sim.c +++ b/robot/sim.c @@ -156,3 +156,51 @@ void print(const char* str) { simprintfunc("print", "\"%s\"", str); } +void lcd_goto_xy(unsigned int x, unsigned int y) { + simprintfunc("lcd_goto_xy", "%u, %u", x, y); +} + +void delay(unsigned long duration) { + return delay_ms(duration); +} + +void delay_ms(unsigned long duration) { + simprintfunc("delay_ms", "%lu", duration); +} + +int read_battery_millivolts() { + simprintfunc("read_battery_millivolts", ""); + return W2_BATTERY_FULL; +} + +unsigned long get_ticks() { + simprintfunc("get_ticks", ""); +#ifdef W2_HOST_LINUX + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + return (now.tv_sec * 1e6) + (now.tv_nsec / 1e3); +#endif +} + +unsigned long ticks_to_microseconds(unsigned long num_ticks) { + simprintfunc("ticks_to_microseconds", "%lu", num_ticks); + return num_ticks; +} + +int read_line() { + return 0; +} + +void play_frequency(unsigned int freq, unsigned int duration, unsigned char volume) { + simprintfunc("play_frequency", "%u, %u, %u", freq, duration, volume); +} + +void calibrate_line_sensors(unsigned char read_mode) { + simprintfunc("calibrate_line_sensors", "%u", read_mode); +} + +unsigned char pololu_3pi_init(unsigned int line_sensor_timeout) { + simprintfunc("pololu_3pi_init", "%u", line_sensor_timeout); + return 0; +} + diff --git a/robot/sim.h b/robot/sim.h index 7d7c091..874a4ad 100644 --- a/robot/sim.h +++ b/robot/sim.h @@ -59,6 +59,7 @@ #define TOP_BUTTON 3 #define BOTTOM_BUTTON 4 #define QTR_EMITTERS_ON 0 +#define IR_EMITTERS_ON 0 /** * simulates pololu library functions for local testing @@ -79,6 +80,16 @@ unsigned char get_single_debounced_button_press(unsigned char buttons); // NOLIN void qtr_read(unsigned int* sensor_values, unsigned char read_mode); // NOLINT unsigned int analog_read(unsigned char channel); // NOLINT void print(const char* str); // NOLINT +void lcd_goto_xy(unsigned int x, unsigned int y); // NOLINT +void delay(unsigned long duration); // NOLINT +void delay_ms(unsigned long duration); // NOLINT +int read_battery_millivolts(); // NOLINT +unsigned long get_ticks(); // NOLINT +unsigned long ticks_to_microseconds(unsigned long num_ticks); // NOLINT +int read_line(); // NOLINT +void play_frequency(unsigned int freq, unsigned int duration, unsigned char volume); // NOLINT +void calibrate_line_sensors(unsigned char read_mode); // NOLINT +unsigned char pololu_3pi_init(unsigned int line_sensor_timeout); // NOLINT void w2_sim_setup(); void w2_sim_cycle_begin(); diff --git a/shared/protocol.h b/shared/protocol.h index 83d9111..4515e0d 100644 --- a/shared/protocol.h +++ b/shared/protocol.h @@ -169,7 +169,7 @@ typedef struct { typedef struct { uint8_t opcode; - w2_e_target_area target_area; + uint8_t target_area; } w2_s_cmd_tarq_rx; #pragma pack(pop) -- cgit v1.2.3