Skip to content

Instantly share code, notes, and snippets.

@kd8bxp
Created August 6, 2022 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kd8bxp/35cc51c0488bbd554908239731d19877 to your computer and use it in GitHub Desktop.
Save kd8bxp/35cc51c0488bbd554908239731d19877 to your computer and use it in GitHub Desktop.
HELP ME!!! I want to send what gets printed to the console out to the uart....I'm getting various errors.
{"x":107, "y":54, "w":35, "h":11, "id":6, "family":16, "cx":123, "cy":59, "rotation":4.878008, "decision_margin":0.141662, "hamming":0, "goodness":0.000000, "x_translation":3.568973, "y_translation":0.019091, "z_translation":-9.150799, "x_rotation":2.946753, "y_rotation":5.268499, "z_rotation":4.878008}
{"x":115, "y":71, "w":44, "h":16, "id":7, "family":16, "cx":135, "cy":79, "rotation":4.780105, "decision_margin":0.223986, "hamming":0, "goodness":0.000000, "x_translation":4.222084, "y_translation":-1.424386, "z_translation":-8.502317, "x_rotation":3.108948, "y_rotation":5.403927, "z_rotation":4.780105}
{"x":66, "y":55, "w":30, "h":11, "id":12, "family":16, "cx":80, "cy":60, "rotation":4.662699, "decision_margin":0.152708, "hamming":0, "goodness":0.000000, "x_translation":0.069529, "y_translation":-0.050373, "z_translation":-10.126225, "x_rotation":3.290249, "y_rotation":5.360118, "z_rotation":4.662699}
{"x":65, "y":72, "w":38, "h":16, "id":13, "family":16, "cx":83, "cy":79, "rotation":4.737180, "decision_margin":0.235322, "hamming":0, "goodness":0.000000, "x_translation":0.238388, "y_translation":-1.483119, "z_translation":-8.448090, "x_rotation":3.175650, "y_rotation":5.389733, "z_rotation":4.737180}
{"x":19, "y":55, "w":34, "h":12, "id":18, "family":16, "cx":37, "cy":61, "rotation":4.791730, "decision_margin":0.183090, "hamming":0, "goodness":0.000000, "x_translation":-3.816703, "y_translation":-0.112855, "z_translation":-10.196960, "x_rotation":3.058419, "y_rotation":5.377745, "z_rotation":4.791730}
{"x":6, "y":73, "w":43, "h":17, "id":19, "family":16, "cx":30, "cy":80, "rotation":4.846455, "decision_margin":0.233223, "hamming":0, "goodness":0.000000, "x_translation":-3.606372, "y_translation":-1.496765, "z_translation":-8.134860, "x_rotation":2.979753, "y_rotation":5.323953, "z_rotation":4.846455}
{"x":106, "y":54, "w":36, "h":11, "id":6, "family":16, "cx":123, "cy":59, "rotation":4.911625, "decision_margin":0.138666, "hamming":0, "goodness":0.000000, "x_translation":3.644424, "y_translation":0.015045, "z_translation":-9.324756, "x_rotation":2.907485, "y_rotation":5.307015, "z_rotation":4.911625}
{"x":115, "y":71, "w":44, "h":16, "id":7, "family":16, "cx":135, "cy":79, "rotation":4.756366, "decision_margin":0.223956, "hamming":0, "goodness":0.000000, "x_translation":4.215088, "y_translation":-1.423224, "z_translation":-8.500789, "x_rotation":3.149373, "y_rotation":5.386641, "z_rotation":4.756366}
{"x":66, "y":55, "w":30, "h":11, "id":12, "family":16, "cx":80, "cy":60, "rotation":4.686912, "decision_margin":0.148382, "hamming":0, "goodness":0.000000, "x_translation":0.078047, "y_translation":-0.053573, "z_translation":-10.352678, "x_rotation":3.251701, "y_rotation":5.390156, "z_rotation":4.686912}
{"x":65, "y":72, "w":38, "h":16, "id":13, "family":16, "cx":83, "cy":79, "rotation":4.725864, "decision_margin":0.233762, "hamming":0, "goodness":0.000000, "x_translation":0.233332, "y_translation":-1.468210, "z_translation":-8.372289, "x_rotation":3.191791, "y_rotation":5.369163, "z_rotation":4.725864}
{"x":19, "y":55, "w":34, "h":12, "id":18, "family":16, "cx":37, "cy":61, "rotation":4.740994, "decision_margin":0.185827, "hamming":0, "goodness":0.000000, "x_translation":-3.795478, "y_translation":-0.115073, "z_translation":-10.107291, "x_rotation":3.134034, "y_rotation":5.382222, "z_rotation":4.740994}
{"x":6, "y":73, "w":43, "h":17, "id":19, "family":16, "cx":30, "cy":80, "rotation":4.847045, "decision_margin":0.235212, "hamming":0, "goodness":0.000000, "x_translation":-3.626786, "y_translation":-1.505832, "z_translation":-8.184102, "x_rotation":2.972013, "y_rotation":5.333889, "z_rotation":4.847045}
{"x":106, "y":54, "w":36, "h":12, "id":6, "family":16, "cx":124, "cy":59, "rotation":4.965443, "decision_margin":0.142976, "hamming":0, "goodness":0.000000, "x_translation":3.638447, "y_translation":0.015567, "z_translation":-9.289454, "x_rotation":2.832773, "y_rotation":5.333557, "z_rotation":4.965443}
{"x":115, "y":71, "w":44, "h":16, "id":7, "family":16, "cx":135, "cy":79, "rotation":4.753424, "decision_margin":0.226714, "hamming":0, "goodness":0.000000, "x_translation":4.212456, "y_translation":-1.421665, "z_translation":-8.495620, "x_rotation":3.152835, "y_rotation":5.386569, "z_rotation":4.753424}
{"x":66, "y":55, "w":30, "h":11, "id":12, "family":16, "cx":80, "cy":60, "rotation":4.658884, "decision_margin":0.149615, "hamming":0, "goodness":0.000000, "x_translation":0.068830, "y_translation":-0.051124, "z_translation":-10.250224, "x_rotation":3.296204, "y_rotation":5.381923, "z_rotation":4.658884}
{"x":65, "y":72, "w":38, "h":16, "id":13, "family":16, "cx":83, "cy":79, "rotation":4.742552, "decision_margin":0.234659, "hamming":0, "goodness":0.000000, "x_translation":0.241599, "y_translation":-1.485430, "z_translation":-8.458374, "x_rotation":3.163172, "y_rotation":5.391254, "z_rotation":4.742552}
{"x":19, "y":55, "w":34, "h":12, "id":18, "family":16, "cx":37, "cy":61, "rotation":4.783628, "decision_margin":0.189063, "hamming":0, "goodness":0.000000, "x_translation":-3.809161, "y_translation":-0.113115, "z_translation":-10.163311, "x_rotation":3.074083, "y_rotation":5.376049, "z_rotation":4.783628}
{"x":6, "y":73, "w":43, "h":17, "id":19, "family":16, "cx":30, "cy":80, "rotation":4.848177, "decision_margin":0.226011, "hamming":0, "goodness":0.000000, "x_translation":-3.626968, "y_translation":-1.506155, "z_translation":-8.181467, "x_rotation":2.970676, "y_rotation":5.334428, "z_rotation":4.848177}
{"x":106, "y":54, "w":36, "h":12, "id":6, "family":16, "cx":124, "cy":59, "rotation":4.966729, "decision_margin":0.136869, "hamming":0, "goodness":0.000000, "x_translation":3.650200, "y_translation":0.012425, "z_translation":-9.311810, "x_rotation":2.826493, "y_rotation":5.337776, "z_rotation":4.966729}
{"x":115, "y":71, "w":44, "h":16, "id":7, "family":16, "cx":135, "cy":79, "rotation":4.755987, "decision_margin":0.227677, "hamming":0, "goodness":0.000000, "x_translation":4.230183, "y_translation":-1.429256, "z_translation":-8.533261, "x_rotation":3.155475, "y_rotation":5.394605, "z_rotation":4.755987}
{"x":66, "y":55, "w":30, "h":11, "id":12, "family":16, "cx":80, "cy":60, "rotation":4.702117, "decision_margin":0.151182, "hamming":0, "goodness":0.000000, "x_translation":0.079833, "y_translation":-0.052301, "z_translation":-10.309992, "x_rotation":3.225177, "y_rotation":5.378967, "z_rotation":4.702117}
{"x":65, "y":72, "w":38, "h":16, "id":13, "family":16, "cx":83, "cy":79, "rotation":4.743033, "decision_margin":0.231272, "hamming":0, "goodness":0.000000, "x_translation":0.243119, "y_translation":-1.490238, "z_translation":-8.484131, "x_rotation":3.162827, "y_rotation":5.398045, "z_rotation":4.743033}
{"x":19, "y":55, "w":34, "h":12, "id":18, "family":16, "cx":37, "cy":61, "rotation":4.772734, "decision_margin":0.188980, "hamming":0, "goodness":0.000000, "x_translation":-3.801966, "y_translation":-0.113477, "z_translation":-10.138271, "x_rotation":3.089350, "y_rotation":5.375279, "z_rotation":4.772734}
{"x":6, "y":73, "w":43, "h":17, "id":19, "family":16, "cx":30, "cy":80, "rotation":4.862228, "decision_margin":0.234496, "hamming":0, "goodness":0.000000, "x_translation":-3.614825, "y_translation":-1.501490, "z_translation":-8.160735, "x_rotation":2.951482, "y_rotation":5.326648, "z_rotation":4.862228}
{"x":106, "y":54, "w":36, "h":12, "id":6, "family":16, "cx":123, "cy":59, "rotation":4.932213, "decision_margin":0.139399, "hamming":0, "goodness":0.000000, "x_translation":3.675063, "y_translation":0.014703, "z_translation":-9.396980, "x_rotation":2.878384, "y_rotation":5.329489, "z_rotation":4.932213}
{"x":115, "y":71, "w":44, "h":16, "id":7, "family":16, "cx":135, "cy":79, "rotation":4.778491, "decision_margin":0.227668, "hamming":0, "goodness":0.000000, "x_translation":4.210288, "y_translation":-1.420319, "z_translation":-8.475029, "x_rotation":3.109630, "y_rotation":5.394194, "z_rotation":4.778491}
{"x":66, "y":55, "w":30, "h":11, "id":12, "family":16, "cx":80, "cy":60, "rotation":4.661058, "decision_margin":0.153858, "hamming":0, "goodness":0.000000, "x_translation":0.068285, "y_translation":-0.051160, "z_translation":-10.158811, "x_rotation":3.292124, "y_rotation":5.364149, "z_rotation":4.661058}
{"x":65, "y":72, "w":38, "h":16, "id":13, "family":16, "cx":83, "cy":79, "rotation":4.708264, "decision_margin":0.236793, "hamming":0, "goodness":0.000000, "x_translation":0.227338, "y_translation":-1.420720, "z_translation":-8.131306, "x_rotation":3.205300, "y_rotation":5.308298, "z_rotation":4.708264}
{"x":19, "y":55, "w":34, "h":12, "id":18, "family":16, "cx":37, "cy":61, "rotation":4.744344, "decision_margin":0.184997, "hamming":0, "goodness":0.000000, "x_translation":-3.754584, "y_translation":-0.112361, "z_translation":-9.994170, "x_rotation":3.132497, "y_rotation":5.366382, "z_rotation":4.744344}
{"x":6, "y":73, "w":43, "h":17, "id":19, "family":16, "cx":30, "cy":80, "rotation":4.868905, "decision_margin":0.231439, "hamming":0, "goodness":0.000000, "x_translation":-3.626642, "y_translation":-1.507272, "z_translation":-8.196636, "x_rotation":2.932245, "y_rotation":5.331038, "z_rotation":4.868905}
{"x":106, "y":54, "w":36, "h":11, "id":6, "family":16, "cx":124, "cy":59, "rotation":4.985612, "decision_margin":0.141649, "hamming":0, "goodness":0.000000, "x_translation":3.580280, "y_translation":0.013544, "z_translation":-9.116656, "x_rotation":2.795932, "y_rotation":5.326523, "z_rotation":4.985612}
{"x":115, "y":71, "w":44, "h":16, "id":7, "family":16, "cx":135, "cy":79, "rotation":4.744773, "decision_margin":0.225287, "hamming":0, "goodness":0.000000, "x_translation":4.211848, "y_translation":-1.422353, "z_translation":-8.496490, "x_rotation":3.167015, "y_rotation":5.381591, "z_rotation":4.744773}
{"x":66, "y":55, "w":30, "h":11, "id":12, "family":16, "cx":80, "cy":60, "rotation":4.721570, "decision_margin":0.157022, "hamming":0, "goodness":0.000000, "x_translation":0.083886, "y_translation":-0.051895, "z_translation":-10.275563, "x_rotation":3.193345, "y_rotation":5.367884, "z_rotation":4.721570}
{"x":65, "y":72, "w":38, "h":16, "id":13, "family":16, "cx":83, "cy":79, "rotation":4.731596, "decision_margin":0.236413, "hamming":0, "goodness":0.000000, "x_translation":0.237364, "y_translation":-1.478346, "z_translation":-8.424411, "x_rotation":3.185031, "y_rotation":5.383935, "z_rotation":4.731596}
{"x":19, "y":55, "w":34, "h":12, "id":18, "family":16, "cx":37, "cy":61, "rotation":4.742529, "decision_margin":0.188224, "hamming":0, "goodness":0.000000, "x_translation":-3.814957, "y_translation":-0.113698, "z_translation":-10.156543, "x_rotation":3.135354, "y_rotation":5.385193, "z_rotation":4.742529}
{"x":6, "y":73, "w":43, "h":17, "id":19, "family":16, "cx":30, "cy":80, "rotation":4.857065, "decision_margin":0.231713, "hamming":0, "goodness":0.000000, "x_translation":-3.610590, "y_translation":-1.499515, "z_translation":-8.151173, "x_rotation":2.957649, "y_rotation":5.326322, "z_rotation":4.857065}
{"x":106, "y":54, "w":36, "h":11, "id":6, "family":16, "cx":123, "cy":59, "rotation":4.919774, "decision_margin":0.139461, "hamming":0, "goodness":0.000000, "x_translation":3.628122, "y_translation":0.014536, "z_translation":-9.273146, "x_rotation":2.886312, "y_rotation":5.306775, "z_rotation":4.919774}
{"x":115, "y":71, "w":44, "h":16, "id":7, "family":16, "cx":135, "cy":79, "rotation":4.764559, "decision_margin":0.227630, "hamming":0, "goodness":0.000000, "x_translation":4.222287, "y_translation":-1.425315, "z_translation":-8.508440, "x_rotation":3.138322, "y_rotation":5.392499, "z_rotation":4.764559}
{"x":66, "y":55, "w":30, "h":11, "id":12, "family":16, "cx":80, "cy":60, "rotation":4.701041, "decision_margin":0.152341, "hamming":0, "goodness":0.000000, "x_translation":0.080805, "y_translation":-0.052993, "z_translation":-10.355846, "x_rotation":3.227489, "y_rotation":5.384954, "z_rotation":4.701041}
{"x":65, "y":72, "w":38, "h":16, "id":13, "family":16, "cx":83, "cy":79, "rotation":4.707662, "decision_margin":0.234988, "hamming":0, "goodness":0.000000, "x_translation":0.226399, "y_translation":-1.413012, "z_translation":-8.090411, "x_rotation":3.203945, "y_rotation":5.296361, "z_rotation":4.707662}
{"x":19, "y":55, "w":34, "h":12, "id":18, "family":16, "cx":37, "cy":61, "rotation":4.786612, "decision_margin":0.182045, "hamming":0, "goodness":0.000000, "x_translation":-3.811873, "y_translation":-0.111803, "z_translation":-10.179206, "x_rotation":3.066217, "y_rotation":5.377636, "z_rotation":4.786612}
{"x":6, "y":73, "w":43, "h":17, "id":19, "family":16, "cx":30, "cy":80, "rotation":4.851059, "decision_margin":0.229206, "hamming":0, "goodness":0.000000, "x_translation":-3.634309, "y_translation":-1.511394, "z_translation":-8.202742, "x_rotation":2.962033, "y_rotation":5.339234, "z_rotation":4.851059}
{"x":106, "y":54, "w":36, "h":12, "id":6, "family":16, "cx":124, "cy":59, "rotation":4.953738, "decision_margin":0.138560, "hamming":0, "goodness":0.000000, "x_translation":3.700454, "y_translation":0.013975, "z_translation":-9.447972, "x_rotation":2.849008, "y_rotation":5.349508, "z_rotation":4.953738}
{"x":115, "y":71, "w":45, "h":16, "id":7, "family":16, "cx":135, "cy":79, "rotation":4.746480, "decision_margin":0.220537, "hamming":0, "goodness":0.000000, "x_translation":4.175475, "y_translation":-1.408822, "z_translation":-8.421731, "x_rotation":3.157503, "y_rotation":5.364995, "z_rotation":4.746480}
{"x":66, "y":55, "w":30, "h":11, "id":12, "family":16, "cx":80, "cy":60, "rotation":4.677542, "decision_margin":0.150031, "hamming":0, "goodness":0.000000, "x_translation":0.074141, "y_translation":-0.051627, "z_translation":-10.234710, "x_rotation":3.267630, "y_rotation":5.372766, "z_rotation":4.677542}
{"x":65, "y":72, "w":38, "h":16, "id":13, "family":16, "cx":83, "cy":79, "rotation":4.724798, "decision_margin":0.237037, "hamming":0, "goodness":0.000000, "x_translation":0.233560, "y_translation":-1.465708, "z_translation":-8.354495, "x_rotation":3.191447, "y_rotation":5.364388, "z_rotation":4.724798}
{"x":19, "y":55, "w":34, "h":12, "id":18, "family":16, "cx":37, "cy":61, "rotation":4.764707, "decision_margin":0.178453, "hamming":0, "goodness":0.000000, "x_translation":-3.824784, "y_translation":-0.115580, "z_translation":-10.202831, "x_rotation":3.091211, "y_rotation":5.389130, "z_rotation":4.764707}
{"x":6, "y":73, "w":43, "h":17, "id":19, "family":16, "cx":30, "cy":80, "rotation":4.865512, "decision_margin":0.229720, "hamming":0, "goodness":0.000000, "x_translation":-3.632701, "y_translation":-1.510739, "z_translation":-8.205216, "x_rotation":2.939958, "y_rotation":5.335160, "z_rotation":4.865512}
{"x":106, "y":54, "w":36, "h":12, "id":6, "family":16, "cx":124, "cy":59, "rotation":5.005362, "decision_margin":0.146986, "hamming":0, "goodness":0.000000, "x_translation":3.556136, "y_translation":0.013159, "z_translation":-9.048112, "x_rotation":2.769314, "y_rotation":5.329933, "z_rotation":5.005362}
{"x":115, "y":71, "w":44, "h":16, "id":7, "family":16, "cx":135, "cy":79, "rotation":4.767027, "decision_margin":0.228669, "hamming":0, "goodness":0.000000, "x_translation":4.221735, "y_translation":-1.424973, "z_translation":-8.505648, "x_rotation":3.135018, "y_rotation":5.395388, "z_rotation":4.767027}
{"x":66, "y":55, "w":30, "h":11, "id":12, "family":16, "cx":80, "cy":60, "rotation":4.679734, "decision_margin":0.153835, "hamming":0, "goodness":0.000000, "x_translation":0.076705, "y_translation":-0.052484, "z_translation":-10.319456, "x_rotation":3.261033, "y_rotation":5.385693, "z_rotation":4.679734}
{"x":65, "y":72, "w":38, "h":16, "id":13, "family":16, "cx":83, "cy":79, "rotation":4.721302, "decision_margin":0.231282, "hamming":0, "goodness":0.000000, "x_translation":0.234698, "y_translation":-1.489743, "z_translation":-8.483359, "x_rotation":3.208599, "y_rotation":5.403346, "z_rotation":4.721302}
{"x":19, "y":55, "w":34, "h":12, "id":18, "family":16, "cx":37, "cy":61, "rotation":4.742947, "decision_margin":0.178361, "hamming":0, "goodness":0.000000, "x_translation":-3.822519, "y_translation":-0.115616, "z_translation":-10.180451, "x_rotation":3.129062, "y_rotation":5.392409, "z_rotation":4.742947}
{"x":6, "y":73, "w":43, "h":17, "id":19, "family":16, "cx":30, "cy":80, "rotation":4.849067, "decision_margin":0.230097, "hamming":0, "goodness":0.000000, "x_translation":-3.609462, "y_translation":-1.498732, "z_translation":-8.140619, "x_rotation":2.971936, "y_rotation":5.325848, "z_rotation":4.849067}
{"x":106, "y":54, "w":36, "h":11, "id":6, "family":16, "cx":124, "cy":59, "rotation":4.942822, "decision_margin":0.139391, "hamming":0, "goodness":0.000000, "x_translation":3.629905, "y_translation":0.013022, "z_translation":-9.267362, "x_rotation":2.855602, "y_rotation":5.319091, "z_rotation":4.942822}
I'm not great with python...
I was able to manage to get the UART working on the M5StickV (original model)
But I can't send the above output to the UART....I get various errors mostly having to do with
OBJECTs and/or converting
I'm working on a indoor navigation robot using april tags.
I'm not completely sure I need all of the above information.
I think at minimum I would need the X, Y, H, ID probably the rotation
But I would like all of it, just in case I need something else.
I was hoping to just get this sent like it is, as a JSON string...but willing to make changes as needed to get it to work.
Using an M5StickV and M5StickC and M5Rover
Thanks for any help and one can give.
#
# AprilTagを検出.
# https://docs.openmv.io/library/omv.image.html#image.image.find_apriltags
#
##################################################
# import
##################################################
import lcd
import sensor
from machine import UART
from Maix import GPIO
from fpioa_manager import *
fm.register(34,fm.fpioa.UART1_TX)
fm.register(35,fm.fpioa.UART1_RX)
#fm.register(board_info.LED_W, fm.fpioa.GPIO3)
uart_out = UART(UART.UART1, 115200,8,None,1, timeout=1000, read_buf_len=4096)
##################################################
# initialize
##################################################
# LCDを初期化
#lcd.init()
# LCDの方向を設定
#lcd.direction(lcd.YX_LRUD)
# カメラを初期化
sensor.reset()
sensor.set_brightness(0)
sensor.set_pixformat(sensor.RGB565) #GRAYSCALE) #RGB565)
sensor.set_framesize(sensor.QQVGA)
#sensor.set_hmirror(0)
sensor.skip_frames(time = 500) # Takes n number of snapshots to let the camera image stabilize
sensor.run(1)
##################################################
# main
##################################################
while True:
# カメラ画像を取得
img = sensor.snapshot()
# AprilTagを検出
res = img.find_apriltags()
# 全ての結果に対して実行
for i in res:
print(i)
#uart_out.write(bytes(i))
#uart_out.write('\n')
# 矩形を描画
img.draw_rectangle(i.x(), i.y(), i.w(), i.h(), color = (255, 0, 0), thickness = 2)
# 十字を描画
img.draw_cross(i.cx(), i.cy(), color = (255, 0, 0), thickness = 2)
# 画像をLCDに描画
#lcd.display(img)
@kd8bxp
Copy link
Author

kd8bxp commented Aug 6, 2022

I think I found the answer to my problem.....
replaced line 47 - 56 with

for i in res:
       print(i)
       uart_out.write(repr(i))
       uart_out.write('\n')
       # 矩形を描画
       img.draw_rectangle(i.x(), i.y(), i.w(), i.h(), color = (255, 0, 0), thickness = 2)
       # 十字を描画
       img.draw_cross(i.cx(), i.cy(), color = (255, 0, 0), thickness = 2)
   # 画像をLCDに描画
   #lcd.display(img)


uart_out.write(repr(i)) seems to have fixed the problem....found that (finally) from
https://www.geeksforgeeks.org/convert-object-to-string-in-python/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment