-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working hardcode controller. Behavior wrinkles (especially when cente…
…ring)
- Loading branch information
1 parent
4cbecdd
commit 9e07412
Showing
4 changed files
with
114 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"python.pythonPath": "C:\\Users\\swimm\\Anaconda3\\envs\\Pagent\\python.exe" | ||
"python.pythonPath": "C:\\Users\\swimm\\Anaconda3\\envs\\pagent_clone\\python.exe" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,52 @@ | ||
import airsim | ||
import numpy as np | ||
from torchvision import transforms | ||
import torch | ||
import PIL | ||
import os | ||
import io | ||
|
||
from Network.HardCode_Controller import HardCode_Controller | ||
|
||
# Check if Connection with Airsim is Good | ||
client = airsim.MultirotorClient() | ||
client = airsim.MultirotorClient() | ||
client.confirmConnection() | ||
client.enableApiControl(True) | ||
client.armDisarm(True) | ||
|
||
# Load CNN Model | ||
loaded_model = torch.load(os.path.join(os.path.abspath(__name__),"..","Network","object_detection","mymodel3.pt"), map_location="cuda:0") # Assumes model is stored in \P-agent\Network\Object_detection | ||
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu') | ||
|
||
#Takeoff and Prepare for instructions | ||
client.takeoffAsync().join() | ||
|
||
done = False | ||
mem = np.zeros([3,1]) | ||
|
||
mem = 0 | ||
while(done == False): | ||
# pts, confidence = CNN(client.simGetImages) # Where pts = [bottomleft, topleft, topright, bottom right] of bounding box | ||
pts = [] | ||
# TODO: Confidence Threshold Check | ||
done, mem = HardCode_Controller(client, pts, mem) # Probably have to call a method after def. | ||
done.policy() | ||
print("I got to the Package!") | ||
# Grab image and convert to RGB tensor | ||
img = client.simGetImage("0", airsim.ImageType.Scene) | ||
f_im = PIL.Image.open(io.BytesIO(img)).convert('RGB') | ||
f_tensor = transforms.ToTensor()(f_im) | ||
|
||
# Feed image into CNN and collect prediction | ||
mask_pred = loaded_model([f_tensor.to(device)]) | ||
if len(mask_pred[0]['boxes']) == 0: # If empty tensor (ie no package) | ||
box_pred = [] | ||
pass | ||
else: | ||
box_pred = mask_pred[0]['boxes'][0] # First tensor is the bounding box coordinates | ||
confidence = mask_pred[0]['scores'][0] | ||
x0, y0, x1, y1 = [int(i) for i in box_pred.tolist()] # Turn into coordinates | ||
box_pred = np.array([[x0,y0],[x1,y1]]) # First set of coordinates is top left of the box and second set is the bottom right | ||
|
||
if confidence == mask_pred[0]['scores'][0] < 0.9: # Confidence threshold check | ||
box_pred = [] | ||
|
||
Controller = HardCode_Controller(client, box_pred, mem) | ||
done, mem, collided = Controller.policy() | ||
|
||
if collided: | ||
print("I hit a wall, dumdum") | ||
if not collided: | ||
print("I got to the Package!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters