Skip to content

Commit

Permalink
feat: add gripper to unity simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
alberto-abarzua committed Nov 18, 2023
1 parent 1779d70 commit 25f567e
Show file tree
Hide file tree
Showing 10 changed files with 336 additions and 61 deletions.
4 changes: 2 additions & 2 deletions controller/src/ribot/control/controller_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ def __init__(self, controller: Any, port: int) -> None:
async def handler(self, websocket: Any, _: str) -> None:
async for message in websocket:
if message.strip() == "get_angles":
angles = self.controller.current_angles
response = Message(MessageOp.STATUS, 0, angles)
angles_tool = list(self.controller.current_angles) + [self.controller.tool_value]
response = Message(MessageOp.STATUS, 0, angles_tool)
await websocket.send(response.encode())

def _start(self) -> None:
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/redux/sagas.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
import { armPoseActions } from '@/redux/ArmPoseSlice';
import api from '@/utils/api';
import instanciatorApi from '@/utils/instanciator_api';
import { call, put, delay, all } from 'redux-saga/effects';

function* fetchApiData() {
try {
// if in the server return

let instanciatorUrl = import.meta.env.VITE_INSTANCIATOR_URL;
console.log('instanciatorUrl', instanciatorUrl);

if (instanciatorUrl && instanciatorUrl !== 'undefined') {
try {
yield call(instanciatorApi.get, '/health_check/');
} catch (error) {
}
}
const response = yield call(api.get, '/settings/status/?degrees=true');
yield put(armPoseActions.updateCurrent(response.data));
} catch (error) {
console.error('Error fetching data:', error);
}
}



function* watchFetchApiData() {
while (true) {
yield call(fetchApiData);
Expand Down
16 changes: 15 additions & 1 deletion instanciator/backend/src/instance_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ def instance_checker_target_fun(self) -> None:
if instance["free"]:
free_instances += 1

if free_instances <= 3:
if time.time() - instance["last_health_check"] > 60 * 3:
self.set_last_health_check(instance_uuid)
self.destroy(instance_uuid)



if free_instances <= 5:
new_uuid = str(uuid.uuid4())
self.instances = instances
new_instance = self.create_instance(new_uuid)
Expand Down Expand Up @@ -186,8 +192,16 @@ def create_instance(self, uuid_str: str) -> Dict[str, Any]:
"time_started": time.time(),
"free": True,
"uuid": uuid_str,
"last_health_check": 0,

}

def set_last_health_check(self, uuid_str: str) -> None:
instances = self.instances
if uuid_str in instances:
instances[uuid_str]["last_health_check"] = time.time()
self.instances = instances

def destroy(self, uuid_str: str) -> None:
if uuid_str in self.instances:
project_name = self.get_project_name(uuid_str)
Expand Down
27 changes: 26 additions & 1 deletion instanciator/backend/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,43 @@ async def destroy_all() -> Dict[str, Any]:
@app.get("/backend_url/")
async def get_backend_port(request: Request, response: Response) -> Dict[str, Any]:
instance_id_cookie = request.cookies.get("instance_id")
uuid = instance_generator.get_uuid()

if not instance_id_cookie:
uuid = instance_generator.get_uuid()
response.set_cookie(
key="instance_id",
value=uuid,
expires=30 * 60,
httponly=True,
)
else:
uuid = instance_id_cookie


instance = instance_generator.get_instance(uuid)
if instance is None:
return {"status": "not found"}
else:
port = instance["ports"]["backend_http_port"]
return {"backend_url": f"{HOST}:{port}", "backend_port": port, "host": HOST}


@app.post("/health_check/")
async def health_check(request: Request) -> Dict[str, Any]:
instance_id_cookie = request.cookies.get("instance_id")

if not instance_id_cookie:
return {"status": "not found"}
else:
uuid = instance_id_cookie

instance_generator.set_last_health_check(uuid)

if instance is None:
return {"status": "not found"}
else:
return {"status": "ok"}




220 changes: 218 additions & 2 deletions unity_arm_simulation/unity_project/arm_sim/Assets/Scenes/MainArm.unity
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,111 @@ PrefabInstance:
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 664d5316e2283294cb82037be15e1dff, type: 3}
--- !u!1 &249885620
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 249885621}
- component: {fileID: 249885624}
- component: {fileID: 249885623}
- component: {fileID: 249885622}
m_Layer: 0
m_Name: grip_2
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &249885621
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 249885620}
m_LocalRotation: {x: -0, y: -0.7071068, z: -0, w: 0.7071068}
m_LocalPosition: {x: -15.1, y: 83.7, z: 30.7}
m_LocalScale: {x: 12, y: 100, z: 3}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1283258106}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!65 &249885622
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 249885620}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &249885623
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 249885620}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 3c04056b46e00394b81ae6de71fec246, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &249885624
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 249885620}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &305204057 stripped
Transform:
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: ed7302eac47e90c4b9a9e4dcd8fd7b04, type: 3}
Expand Down Expand Up @@ -405,6 +510,12 @@ PrefabInstance:
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects:
- targetCorrespondingSourceObject: {fileID: -8679921383154817045, guid: e65a6f96cd755904d9286502a0d87455, type: 3}
insertIndex: 0
addedObject: {fileID: 1813818385}
- targetCorrespondingSourceObject: {fileID: -8679921383154817045, guid: e65a6f96cd755904d9286502a0d87455, type: 3}
insertIndex: 1
addedObject: {fileID: 249885621}
- targetCorrespondingSourceObject: {fileID: -8679921383154817045, guid: e65a6f96cd755904d9286502a0d87455, type: 3}
insertIndex: -1
addedObject: {fileID: 781846070}
Expand Down Expand Up @@ -839,7 +950,7 @@ Camera:
height: 1
near clip plane: 0.3
far clip plane: 3000
field of view: 75.8
field of view: 77.6
orthographic: 0
orthographic size: 5
m_Depth: -1
Expand All @@ -865,7 +976,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 963194225}
m_LocalRotation: {x: 0.050638843, y: 0.8644719, z: -0.08656927, w: 0.49257466}
m_LocalPosition: {x: -430, y: 471, z: 364}
m_LocalPosition: {x: -374, y: 337, z: 512}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
Expand Down Expand Up @@ -1398,6 +1509,111 @@ Transform:
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: 801c6a1f3001210448910b54618eed9b, type: 3}
m_PrefabInstance: {fileID: 918204848}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1813818384
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1813818385}
- component: {fileID: 1813818388}
- component: {fileID: 1813818387}
- component: {fileID: 1813818386}
m_Layer: 0
m_Name: grip_1
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1813818385
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1813818384}
m_LocalRotation: {x: -0, y: -0.7071068, z: -0, w: 0.7071068}
m_LocalPosition: {x: -16.7, y: 82.8, z: -31.6}
m_LocalScale: {x: 12, y: 100, z: 3}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1283258106}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!65 &1813818386
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1813818384}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &1813818387
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1813818384}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 3c04056b46e00394b81ae6de71fec246, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &1813818388
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1813818384}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1001 &1835944273
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down
Loading

0 comments on commit 25f567e

Please sign in to comment.