latest pushes

This commit is contained in:
2024-12-18 10:08:35 -05:00
parent 378a112ab5
commit b3a416b2bc
5 changed files with 438 additions and 137 deletions

View File

@ -19,27 +19,58 @@ import argparse
import json
import sys
def make_bellande_particles_request(particle, movement=None, world=None, count=None):
url = "https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particles/bellande_particles"
def make_bellande_particle_move_request(particle_state, rotation1, translation, rotation2):
url = "https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/move"
# Convert string inputs to lists/dicts if they're strings
if isinstance(particle, str):
particle = json.loads(particle)
if isinstance(movement, str):
movement = json.loads(movement)
if isinstance(world, str):
world = json.loads(world)
payload = {
"particle": particle,
"movement": movement,
"world": world,
"count": count,
"particle": {
"x": particle_state[0],
"y": particle_state[1],
"heading": particle_state[2],
"weight": particle_state[3] if len(particle_state) > 3 else 1.0
},
"rotation1": rotation1,
"translation": translation,
"rotation2": rotation2,
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
}
return send_request(url, payload)
def make_bellande_particle_read_markers_request(particle_state, world_info):
url = "https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/read_markers"
payload = {
"particle": {
"x": particle_state[0],
"y": particle_state[1],
"heading": particle_state[2],
"weight": particle_state[3] if len(particle_state) > 3 else 1.0
},
"world": world_info,
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
}
return send_request(url, payload)
def make_bellande_particle_create_random_request(count, world_info):
url = "https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/create_random"
payload = {
"count": count,
"world": world_info,
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
}
return send_request(url, payload)
def send_request(url, payload):
headers = {
'accept': 'application/json',
'Content-Type': 'application/json'
@ -54,25 +85,58 @@ def make_bellande_particles_request(particle, movement=None, world=None, count=N
sys.exit(1)
def main():
parser = argparse.ArgumentParser(description="Run Bellande Particles API")
parser.add_argument("--particle", required=True,
help="Particle state as JSON-formatted list [x, y, heading, weight]")
parser.add_argument("--movement",
help="Movement parameters as JSON-formatted list [rotation1, translation, rotation2]")
parser.add_argument("--world",
help="world information as JSON object with width, height, and markers")
parser.add_argument("--count", type=int,
help="Particle count for random generation")
parser = argparse.ArgumentParser(description="Run Bellande Particle API")
subparsers = parser.add_subparsers(dest='command', required=True)
# Move command
move_parser = subparsers.add_parser('move', help='Move particle')
move_parser.add_argument("--particle-state", required=True,
help="Particle state as JSON-formatted list [x, y, heading, weight]")
move_parser.add_argument("--rotation1", type=float, required=True,
help="First rotation angle")
move_parser.add_argument("--translation", type=float, required=True,
help="Translation distance")
move_parser.add_argument("--rotation2", type=float, required=True,
help="Second rotation angle")
# Read markers command
read_parser = subparsers.add_parser('read-markers', help='Read markers')
read_parser.add_argument("--particle-state", required=True,
help="Particle state as JSON-formatted list [x, y, heading, weight]")
read_parser.add_argument("--world", required=True,
help="World information as JSON object")
# Create random command
random_parser = subparsers.add_parser('create-random', help='Create random particles')
random_parser.add_argument("--count", type=int, required=True,
help="Number of particles to create")
random_parser.add_argument("--world", required=True,
help="World information as JSON object")
args = parser.parse_args()
try:
result = make_bellande_particles_request(
args.particle,
args.movement,
args.world,
args.count
)
if args.command == 'move':
particle_state = json.loads(args.particle_state)
result = make_bellande_particle_move_request(
particle_state,
args.rotation1,
args.translation,
args.rotation2
)
elif args.command == 'read-markers':
particle_state = json.loads(args.particle_state)
world_info = json.loads(args.world)
result = make_bellande_particle_read_markers_request(
particle_state,
world_info
)
elif args.command == 'create-random':
world_info = json.loads(args.world)
result = make_bellande_particle_create_random_request(
args.count,
world_info
)
print(json.dumps(result, indent=2))
except json.JSONDecodeError as e: