Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Josiah #7

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build image

on:
push:
branches: [ main ]
branches: [ master ]
tags:
- "*"
workflow_dispatch:
Expand Down
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true
},
"hide-files.files": []
}
Binary file added __pycache__/backend.cpython-310.pyc
Binary file not shown.
Binary file added __pycache__/main.cpython-310.pyc
Binary file not shown.
Binary file added __pycache__/spot_controller.cpython-310.pyc
Binary file not shown.
13 changes: 13 additions & 0 deletions backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from fastapi import FastAPI

app = FastAPI()

@app.post("/")
async def handle_command(cmd: str):
cmd = input()
if cmd == "0":
return {cmd}
elif cmd == "1":
return {cmd}
else:
return {"Invalid input. Please enter a valid cmd."}
32 changes: 8 additions & 24 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time
from spot_controller import SpotController
import cv2
from req import fetch

ROBOT_IP = "10.0.0.3"#os.environ['ROBOT_IP']
SPOT_USERNAME = "admin"#os.environ['SPOT_USERNAME']
Expand All @@ -17,40 +18,23 @@ def capture_image():


def main():
#example of using micro and speakers
print("Start recording audio")
sample_name = "aaaa.wav"
cmd = f'arecord -vv --format=cd --device={os.environ["AUDIO_INPUT_DEVICE"]} -r 48000 --duration=10 -c 1 {sample_name}'
print(cmd)
os.system(cmd)
print("Playing sound")
os.system(f"ffplay -nodisp -autoexit -loglevel quiet {sample_name}")

# # Capture image

# Use wrapper in context manager to lease control, turn on E-Stop, power on the robot and stand up at start
# and to return lease + sit down at the end
with SpotController(username=SPOT_USERNAME, password=SPOT_PASSWORD, robot_ip=ROBOT_IP) as spot:
response = fetch("/", method='POST')
print(response)

time.sleep(2)
capture_image()
# Move head to specified positions with intermediate time.sleep
spot.move_head_in_points(yaws=[0.2, 0],
pitches=[0.3, 0],
rolls=[0.4, 0],
sleep_after_point_reached=1)
capture_image()
time.sleep(3)
spot.move_head_in_points(yaws=[0, 0.4],
pitches=[0, 0.5],
rolls=[0, 0.7],
sleep_after_point_reached=1)

# Make Spot to move by goal_x meters forward and goal_y meters left
spot.move_to_goal(goal_x=0.5, goal_y=0)
time.sleep(3)
capture_image()

# Control Spot by velocity in m/s (or in rad/s for rotation)
spot.move_by_velocity_control(v_x=-0.3, v_y=0, v_rot=0, cmd_duration=2)
capture_image()
time.sleep(3)



if __name__ == '__main__':
Expand Down
27 changes: 27 additions & 0 deletions req.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import http.client

def fetch(path = "/", method='GET'):
# Url
url='http://192.168.2.189:8000'

# Define the URL and headers
headers = {}

# Create an HTTP connection
conn = http.client.HTTPConnection(url.split("/")[2])

# Send a GET request
conn.request("GET", path, headers=headers)

# Get the response
response = conn.getresponse()

# Print the response status and data
print("Status:", response.status, response.reason)
data = response.read()
print("Data:", data.decode())

# Close the connection
conn.close()

print(fetch())