-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-python-protobuf.py
More file actions
88 lines (62 loc) · 2.81 KB
/
Copy pathbasic-python-protobuf.py
File metadata and controls
88 lines (62 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# this python script uses python files generated by protobuf
# to install on windows, go to https://github.com/protocolbuffers/protobuf/releases and download for your architecture
# you can add it to your PATH using for example :
# [Environment]::SetEnvironmentVariable('Path', $env:Path + ";C:\Users\{your user}\Downloads\protoc-24.4-win64\bin", [EnvironmentVariableTarget]::User)
# then, you can generate python files using
# protoc -I=protobuf/ --python_out=protobuf protobuf/telemetry.proto
# Be careful to run this with "python3 basic-python-protobuf.py" and not "python" on the Jetson Nano, which still uses
# python 2.7 :-/
import socket
import telemetry_pb2 as telemetry_pb2
import random
import time
from google.protobuf.text_format import MessageToString
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# to communicate with the robot throught ethernet, you must first set up your internet connection, for example
# sudo ifconfig enp56s0 up 192.168.2.106 netmask 255.255.255.0
# On Windows 11: Settings => Network & Internet => Ethernet =>
# IP assignment => Edit => Manual
# 192.168.2.106,
# Subnet mask: netmask 255.255.255.0
# sock.bind(("YOUR IP HERE", 5005))
sock.bind(("192.168.2.106", 5005))
sock.setblocking(0)
while True:
high_order = telemetry_pb2.VitiroverHighLevelOrder()
high_order.speed = 50 + random.randint(0,50)
# print(high_order.speed)
high_order.back_axle_angle = 0
high_order.turning_mode = telemetry_pb2.MANUAL
order = telemetry_pb2.VitiroverOrder()
order.high_level_order.CopyFrom(high_order)
data = order.SerializeToString()
# Be careful if you want to try mower order as it will start the mowers.
# Check that no object (or fingers) are next to them
# Vitirover denies all reponsability in case of injury
# mower_order = telemetry_pb2.VitiroverMowerOrder()
# mower_order.left_mower_speed = 50
# mower_order.right_mower_speed = 50
# mower_order.control_mode = telemetry_pb2.PWM
# mower_order_container = telemetry_pb2.VitiroverOrder()
# mower_order_container.mower_order.CopyFrom(mower_order)
# mower_data = mower_order_container.SerializeToString()
try:
sock.sendto(data, ("192.168.1.42", 5005))
# sock.sendto(mower_data, ("192.168.1.42", 5005))
except BlockingIOError:
print("erreur on sendto")
pass
telemetry_data = None
while True:
try:
data, addr = sock.recvfrom(20000) # Buffer size
telemetry_data = telemetry_pb2.VitiroverTelemetry()
except BlockingIOError:
# Plus de messages dans le buffer, sortir de la boucle
break
if telemetry_data != None:
telemetry_data.ParseFromString(data)
# Afficher quelques valeurs
print(MessageToString(telemetry_data))
time.sleep(0.5)
# exit()