summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-04-26 22:29:51 +0200
committerlonkaars <loek@pipeframe.xyz>2022-04-26 22:29:51 +0200
commit4d58ddd03b22dab33f37d1916fc94e6d6a875c87 (patch)
tree942e1fc0a74c20a64637750d99da55d5dfa177bf
parentf6272349aedb3c09e8e5a964f6ea4064bf9a2e0a (diff)
debug maps
-rw-r--r--.gitignore1
-rw-r--r--maps/map1.mapbin0 -> 84 bytes
-rw-r--r--maps/map1.txt16
-rw-r--r--maps/map2.mapbin0 -> 17 bytes
-rw-r--r--maps/map2.txt5
-rwxr-xr-xmaps/mapgen.py31
-rwxr-xr-xmaps/mapprint.py24
-rw-r--r--maps/readme.md32
8 files changed, 109 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 774fe47..d493881 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
compile_commands.json
+__pycache__
*.o
robot/out.hex
robot/a.out
diff --git a/maps/map1.map b/maps/map1.map
new file mode 100644
index 0000000..980c069
--- /dev/null
+++ b/maps/map1.map
Binary files differ
diff --git a/maps/map1.txt b/maps/map1.txt
new file mode 100644
index 0000000..37ab452
--- /dev/null
+++ b/maps/map1.txt
@@ -0,0 +1,16 @@
+c559e59c98
+ac16f163aa
+aac92c553a
+6ba6969c9a
+c369ac7be3
+69cba2c3e9
+c3aae9ac3a
+2c3a26361a
+c38a8c559a
+6d3673c532
+cfddddf988
+efff777baa
+eff3000aaa
+eff9000efb
+efffdddbaa
+6777777322
diff --git a/maps/map2.map b/maps/map2.map
new file mode 100644
index 0000000..c7777c9
--- /dev/null
+++ b/maps/map2.map
Binary files differ
diff --git a/maps/map2.txt b/maps/map2.txt
new file mode 100644
index 0000000..6465c5a
--- /dev/null
+++ b/maps/map2.txt
@@ -0,0 +1,5 @@
+c5559
+ac59a
+aa8aa
+a63aa
+6553a
diff --git a/maps/mapgen.py b/maps/mapgen.py
new file mode 100755
index 0000000..a7e6817
--- /dev/null
+++ b/maps/mapgen.py
@@ -0,0 +1,31 @@
+import sys
+from struct import pack
+
+def mapgen(filename):
+ file = open(filename, 'r')
+ target = open(filename + '.map', 'wb')
+ contents = file.read()
+
+ lines = contents.strip().split("\n")
+ target.write(pack('>H', len(lines[0])))
+ target.write(pack('>H', len(lines)))
+
+ first_nibble = False
+ temp_byte = 0
+ for char in contents.replace('\n', '').strip():
+ first_nibble = not first_nibble
+ num = int(char, 16)
+ temp_byte |= num << (4 * first_nibble)
+ if not first_nibble:
+ target.write(pack('B', temp_byte))
+ temp_byte = 0
+ if first_nibble: target.write(pack('B', temp_byte))
+
+ file.close()
+ target.close()
+
+if __name__ == "__main__":
+ if len(sys.argv) > 1:
+ mapgen(sys.argv[1])
+ else:
+ exit(1)
diff --git a/maps/mapprint.py b/maps/mapprint.py
new file mode 100755
index 0000000..4b56db6
--- /dev/null
+++ b/maps/mapprint.py
@@ -0,0 +1,24 @@
+import sys
+from struct import unpack
+
+def mapprint(filename):
+ file = open(filename, 'rb')
+ contents = file.read()
+ file.close()
+
+ width, height = unpack('>HH', contents[0:4])
+
+ for y in range(height):
+ for x in range(width):
+ nibble = x + y * width
+ byte = int(nibble / 2)
+ shift = byte * 2 - nibble + 1
+ num = (contents[4 + byte] & (0xf << 4 * shift)) >> 4 * shift
+ print(" ─│┘──└┴│┐│┤┌┬├┼"[num], end='')
+ print("\n", end='')
+
+if __name__ == "__main__":
+ if len(sys.argv) > 1:
+ mapprint(sys.argv[1])
+ else:
+ exit(1)
diff --git a/maps/readme.md b/maps/readme.md
new file mode 100644
index 0000000..85f94b0
--- /dev/null
+++ b/maps/readme.md
@@ -0,0 +1,32 @@
+# maps
+
+this directory contains map files. a .map file contains a binary representation
+of a maze, and can be sent to the robot over the wireless serial connection.
+map files have the following structure: first the width of the map as an
+unsigned 16-bit integer, then the height of the map also as an unsigned 16-bit
+integer. the rest of the file is the map content in reading order, where each
+byte contains two (nibble) map tiles. tiles are stored in the most significant
+portion of the byte first, so the last byte of a map file containing an uneven
+amount of tiles would look like `0x?0`.
+
+example tile:
+
+```
+┌───────┐ ┌───┬───┐
+│ b │ │ │ │
+│ a c │ │ └───┤
+│ d │ │ │
+└───────┘ └───────┘
+ 0bDCBA 0b0110 (0x6)
+```
+
+garbage python scripts for generating and viewing these maps are included.
+[this](https://www.figma.com/file/GUKV1am9sqWpPoes9h8Ram/robotrun?node-id=0%3A1)
+figma file can be used to create a map, and then read out the hexadecimal
+notation for the map. google drive ocr works well enough to read out the red
+characters if you turn off path visibility in the figma document. figma also
+allows pdf export so you can print the maps, but the tiles are 24x24 pixels,
+not robot-sized (one tile is supposed to have about the same width and height
+as the robot's diameter). but maybe i'll make another script that stitches
+together the map tiles as svg, and then converts the whole thing to pdf.
+