Skip to content

Instantly share code, notes, and snippets.

## Functions to calculate elevation directly given camera intrensics and desired GSD
# Ref: https://poe.com/s/1QaptXvkCTIzmufSBmSA
def calculate_camera_elevation(gsd_cm_px, focal_length_mm, sensor_width_mm, image_width_px):
"""
Calculate the camera elevation given the GSD.
:param gsd_cm_px: Ground Sampling Distance in cm/pixel
:param focal_length_mm: Camera focal length in mm
:param sensor_width_mm: Camera sensor width in mm
:param image_width_px: Width of the image in pixels
#include <unistd.h>
#include <time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
# on the target device, run the following command to download and run their daemon service (if you cant run their service, say you dont have systemd, run it manually with zerotier-one -d)
curl -s 'https://raw.githubusercontent.com/zerotier/ZeroTierOne/master/doc/contact%40zerotier.com.gpg' | gpg --import && \
if z=$(curl -s 'https://install.zerotier.com/' | gpg); then echo "$z" | sudo bash; fi
# check status with their cli
zerotier-cli info
# go to their web interface and create a network, copy the network id
# on the target machine, join the network with their cli and the networkid
DEBUG:root:Node.send_message(): sent uavcan.protocol.NodeStatus(uptime_sec=819, health=0, mode=0, sub_mode=0, vendor_specific_status_code=0)
DEBUG:root:Node.send_message(): sent uavcan.protocol.NodeStatus(uptime_sec=820, health=0, mode=0, sub_mode=0, vendor_specific_status_code=0)
DEBUG:root:Node.send_message(): sent uavcan.protocol.NodeStatus(uptime_sec=820, health=0, mode=0, sub_mode=0, vendor_specific_status_code=0)
DEBUG:root:Node.send_message(): sent uavcan.protocol.NodeStatus(uptime_sec=821, health=0, mode=0, sub_mode=0, vendor_specific_status_code=0)
DEBUG:root:Node.send_message(): sent uavcan.protocol.NodeStatus(uptime_sec=821, health=0, mode=0, sub_mode=0, vendor_specific_status_code=0)
DEBUG:root:Node.send_message(): sent uavcan.protocol.NodeStatus(uptime_sec=822, health=0, mode=0, sub_mode=0, vendor_specific_status_code=0)
DEBUG:root:Node.send_message(): sent uavcan.protocol.NodeStatus(uptime_sec=822, health=0, mode=0, sub_mode=0, vendor_specific_status_code=0)
DEBUG:root:Node.send_message(): sent
node.listen('/dev/ttyACM0')
DEBUG:root:Node._recv_frame(): received Transfer(id=19, source_node_id=1, dest_node_id=None, transfer_priority=16, payload=uavcan.protocol.NodeStatus(uptime_sec=627, health=0, mode=0, sub_mode=0, vendor_specific_status_code=0))
DEBUG:root:Node._recv_frame(): received Transfer(id=18, source_node_id=1, dest_node_id=None, transfer_priority=1, payload=uavcan.protocol.GlobalTimeSync(previous_transmission_timestamp_usec=628552917))
DEBUG:root:Node._recv_frame(): received Transfer(id=1, source_node_id=125, dest_node_id=None, transfer_priority=30, payload=uavcan.protocol.NodeStatus(uptime_sec=2, health=0, mode=1, sub_mode=0, vendor_specific_status_code=0))
DEBUG:root:Node.send_message(): sent uavcan.protocol.NodeStatus(uptime_sec=0, health=0, mode=0, sub_mode=0, vendor_specific_status_code=0)
DEBUG:root:Node._recv_frame(): received Transfer(id=16, source_node_id=1, dest_node_id=127, transfer_priority=30, payload=uavcan.protocol.GetNodeInfo())
DEBUG:root:Node.send_message(): sent uavcan.pr
>>> node.listen('/dev/ttyACM0')
DEBUG:root:Node._recv_frame(): received Transfer(id=0, source_node_id=0, dest_node_id=None, transfer_priority=30, payload=uavcan.protocol.dynamic_node_id.Allocation(node_id=0, first_part_of_unique_id=1, unique_id=ArrayValue(type=saturated uint8[<=16], tao=True, items=[35, 0, 58, 0, 17, 81])))
DEBUG:root:Node._recv_frame(): received Transfer(id=31, source_node_id=1, dest_node_id=None, transfer_priority=30, payload=uavcan.protocol.dynamic_node_id.Allocation(node_id=0, first_part_of_unique_id=0, unique_id=ArrayValue(type=saturated uint8[<=16], tao=True, items=[35, 0, 58, 0, 17, 81])))
DEBUG:root:Node._recv_frame(): received Transfer(id=1, source_node_id=0, dest_node_id=None, transfer_priority=30, payload=uavcan.protocol.dynamic_node_id.Allocation(node_id=0, first_part_of_unique_id=0, unique_id=ArrayValue(type=saturated uint8[<=16], tao=True, items=[52, 51, 49, 48, 55, 48])))
DEBUG:root:Node._recv_frame(): received Transfer(id=2, source_node_id=0, dest_node_id=None, transfer_priori
>>> node.listen('/dev/ttyACM0')
DEBUG:root:Node.send_message(): sent uavcan.protocol.NodeStatus(uptime_sec=0, health=0, mode=0, sub_mode=0, vendor_specific_status_code=0)
DEBUG:root:Node._recv_frame(): received Transfer(id=17, source_node_id=1, dest_node_id=127, transfer_priority=30, payload=uavcan.protocol.GetNodeInfo())
DEBUG:root:Node._recv_frame(): received Transfer(id=2, source_node_id=1, dest_node_id=None, transfer_priority=16, payload=uavcan.protocol.NodeStatus(uptime_sec=194, health=0, mode=0, sub_mode=0, vendor_specific_status_code=0))
DEBUG:root:Node._recv_frame(): received Transfer(id=1, source_node_id=1, dest_node_id=None, transfer_priority=1, payload=uavcan.protocol.GlobalTimeSync(previous_transmission_timestamp_usec=195833789))
DEBUG:root:Node.send_message(): sent uavcan.protocol.NodeStatus(uptime_sec=1, health=0, mode=0, sub_mode=0, vendor_specific_status_code=0)
DEBUG:root:Node._recv_frame(): received Transfer(id=18, source_node_id=1, dest_node_id=127, transfer_priority=30, payload=uavcan.prot
>>> import uavcan
>>>
>>>
>>> uavcan.load_dsdl()
>>> import logging
>>> logging.root.setLevel(logging.DEBUG)
>>> import uavcan.node
>>> node = uavcan.node.Node([])
>>>
>>>