mirror of
https://github.com/Astatin3/photonvision-2025.0.0-beta-6.git
synced 2026-06-09 00:28:06 -06:00
Initial commit
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
###
|
||||
# Alternative ARM Runner installer to setup PhotonVision JAR
|
||||
# for ARM based builds such as Raspberry Pi, Orange Pi, etc.
|
||||
# This assumes that the image provided to arm-runner-action contains
|
||||
# the servicefile needed to auto-launch PhotonVision.
|
||||
###
|
||||
NEW_JAR=$(realpath $(find . -name photonvision\*-linuxarm64.jar))
|
||||
echo "Using jar: " $(basename $NEW_JAR)
|
||||
|
||||
DEST_PV_LOCATION=/opt/photonvision
|
||||
sudo mkdir -p $DEST_PV_LOCATION
|
||||
sudo cp $NEW_JAR ${DEST_PV_LOCATION}/photonvision.jar
|
||||
@@ -0,0 +1,91 @@
|
||||
import argparse
|
||||
from time import sleep
|
||||
|
||||
import ntcore
|
||||
from tabulate import tabulate
|
||||
|
||||
|
||||
def list_topics(inst: ntcore.NetworkTableInstance, root: str):
|
||||
topics = inst.getTable(root).getTopics()
|
||||
subtables = inst.getTable(root).getSubTables()
|
||||
|
||||
print(f"Topics under {root}")
|
||||
print(
|
||||
tabulate(
|
||||
[
|
||||
[topic.getName(), topic.getType().name, topic.getTypeString()]
|
||||
for topic in topics
|
||||
],
|
||||
headers=["Topic Name", "Type", "Type String"],
|
||||
)
|
||||
)
|
||||
print("")
|
||||
print(f"Tables under {root}")
|
||||
print(tabulate([[table] for table in subtables], headers=["Table Name"]))
|
||||
print("")
|
||||
|
||||
|
||||
def print_topic(inst: ntcore.NetworkTableInstance, topic: str):
|
||||
sub = inst.getTopic(topic).genericSubscribe(
|
||||
options=ntcore.PubSubOptions(sendAll=True, pollStorage=20)
|
||||
)
|
||||
print("")
|
||||
print(f"Subscribed to {topic}, typestring '{sub.getTopic().getTypeString()}'")
|
||||
print(f"Properties:")
|
||||
print(sub.getTopic().getProperties())
|
||||
print("")
|
||||
|
||||
start_time = ntcore._now()
|
||||
count = 0
|
||||
while True:
|
||||
now = ntcore._now()
|
||||
new_count = len(sub.readQueue())
|
||||
count = count + new_count
|
||||
|
||||
hz = count / float(max(now - start_time, 0.1) * 1e-6)
|
||||
|
||||
print(f"{topic} = {sub.get().value()} (rate={hz:.1f}hz, samples={count})")
|
||||
sleep(1)
|
||||
|
||||
|
||||
def connect(inst: ntcore.NetworkTableInstance, server: str):
|
||||
inst.stopServer()
|
||||
inst.setServer(server)
|
||||
inst.startClient4("catnt")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Cat a topic")
|
||||
parser.add_argument(
|
||||
"--echo", type=str, help="Fully qualified topic name", required=False
|
||||
)
|
||||
parser.add_argument(
|
||||
"--server",
|
||||
type=str,
|
||||
default="127.0.0.1",
|
||||
help="IP address of the NT4 server",
|
||||
required=False,
|
||||
)
|
||||
parser.add_argument("--list", help="List all topics", required=False)
|
||||
|
||||
args = parser.parse_args()
|
||||
inst = ntcore.NetworkTableInstance.getDefault()
|
||||
|
||||
connect(inst, args.server)
|
||||
# retained to keep the subscriber alive
|
||||
topicNameSubscriber = ntcore.MultiSubscriber(
|
||||
inst, ["/"], ntcore.PubSubOptions(topicsOnly=True)
|
||||
)
|
||||
sleep(1)
|
||||
|
||||
while not inst.isConnected():
|
||||
sleep(0.1)
|
||||
|
||||
if args.list:
|
||||
list_topics(inst, args.list)
|
||||
if args.echo:
|
||||
print_topic(inst, args.echo)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Executable
+71
@@ -0,0 +1,71 @@
|
||||
if [ "$#" -ne 2 ]; then
|
||||
echo "Illegal number of parameters -- expected (Image release URL) (image suffix)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 1st arg should be the release to download the image template from. The release ought to only have one
|
||||
# artifact for a "xz" image.
|
||||
|
||||
NEW_JAR=$(realpath $(find . -name photonvision\*-linuxarm64.jar))
|
||||
echo "Using jar: " $NEW_JAR
|
||||
echo "Downloading image from" $1
|
||||
sudo apt-get install -y xz-utils
|
||||
wget -q $1
|
||||
ls
|
||||
FILE_NAME=$(ls | grep *.xz)
|
||||
|
||||
if [ -z "$FILE_NAME" ]
|
||||
then
|
||||
echo "Could not locate image archive!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Downloaded " $FILE_NAME " -- decompressing now..."
|
||||
xz -T0 -v --decompress $FILE_NAME
|
||||
IMAGE_FILE=$(ls | grep *.img)
|
||||
ls
|
||||
|
||||
if [ -z "$FILE_NAME" ]
|
||||
then
|
||||
echo "Could not locate unzipped image!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Unzipped image: " $IMAGE_FILE " -- mounting"
|
||||
TMP=$(mktemp -d)
|
||||
LOOP=$(sudo losetup --show -fP "${IMAGE_FILE}")
|
||||
echo "Image mounted! Copying jar..."
|
||||
sudo mount ${LOOP}p2 $TMP
|
||||
pushd .
|
||||
cd $TMP/opt/photonvision
|
||||
sudo cp $NEW_JAR photonvision.jar
|
||||
|
||||
echo "Jar updated! Creating service..."
|
||||
|
||||
cd $TMP/etc/systemd/system/multi-user.target.wants
|
||||
sudo bash -c "printf \
|
||||
\"[Unit]
|
||||
Description=Service that runs PhotonVision
|
||||
|
||||
[Service]
|
||||
WorkingDirectory=/opt/photonvision
|
||||
ExecStart=/usr/bin/java -Xmx512m -jar /opt/photonvision/photonvision.jar
|
||||
ExecStop=/bin/systemctl kill photonvision
|
||||
Type=simple
|
||||
Restart=on-failure
|
||||
RestartSec=1
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target\" > photonvision.service"
|
||||
|
||||
popd
|
||||
|
||||
echo "Service created!"
|
||||
|
||||
sudo umount ${TMP}
|
||||
sudo rmdir ${TMP}
|
||||
NEW_IMAGE=$(basename "${NEW_JAR/.jar/_$2.img}")
|
||||
echo "Renaming image " $IMAGE_FILE " -> " $NEW_IMAGE
|
||||
mv $IMAGE_FILE $NEW_IMAGE
|
||||
xz -T0 -v -z $NEW_IMAGE
|
||||
mv $NEW_IMAGE.xz $(basename "${NEW_JAR/.jar/-image_$2.xz}")
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
# The install script is now in photon-image-modifier
|
||||
# this downloads and runs that install script for people using the old short URL
|
||||
wget -q https://raw.githubusercontent.com/PhotonVision/photon-image-modifier/master/install.sh -O ./real_install.sh
|
||||
chmod +x ./real_install.sh
|
||||
./real_install.sh "$@"
|
||||
rm ./real_install.sh
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
echo "This script must be run as root" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -rf /opt/photonvision/
|
||||
echo "Uninstalling systemd service..."
|
||||
systemctl stop photonvision
|
||||
systemctl disable photonvision
|
||||
rm /lib/systemd/system/photonvision.service
|
||||
rm /etc/systemd/system/photonvision.service
|
||||
systemctl daemeon-reload
|
||||
systemctl reset-failed
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Check for root
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
echo "This script must be run as root" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for internet connection
|
||||
wget -q --spider http://google.com
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Internet connection OK"
|
||||
else
|
||||
echo "This script requires an Internet connection! Exiting"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Stopping PhotonVision service"
|
||||
systemctl stop photonvision
|
||||
|
||||
echo "Downloading and installing latest stable release of PhotonVision..."
|
||||
cd /opt/photonvision
|
||||
rm photonvision.jar
|
||||
curl -sk https://api.github.com/repos/photonvision/photonvision/releases/latest |
|
||||
grep "browser_download_url.*jar" |
|
||||
cut -d : -f 2,3 |
|
||||
tr -d '"' |
|
||||
wget -qi - -O photonvision.jar
|
||||
|
||||
echo "Starting PhotonVision service"
|
||||
systemctl start photonvision
|
||||
|
||||
echo "PhotonVision update successful!"
|
||||
Reference in New Issue
Block a user