Browse Source

Update Description script using subprocess module

pull/75/head
Mohamed Fazil 2 years ago
parent
commit
652bf33801
1 changed files with 23 additions and 4 deletions
  1. +23
    -4
      stretch_description/batch/update_description.py

+ 23
- 4
stretch_description/batch/update_description.py View File

@ -5,17 +5,36 @@ This script updates the Mesh files and URDF file specific to a robot batch.
import os import os
from os.path import exists from os.path import exists
import stretch_body.hello_utils as hu import stretch_body.hello_utils as hu
import subprocess
import sys
def run_cmd(cmdstr):
process = subprocess.run(cmdstr, capture_output=True, text=True, shell=True)
if process.returncode != 0:
print("update_description.py ERROR: {}".format(process.stderr), file=sys.stderr)
sys.exit(1)
return process
if exists(hu.get_fleet_directory() + 'stretch_configuration_params.yaml'): if exists(hu.get_fleet_directory() + 'stretch_configuration_params.yaml'):
batch_name = hu.read_fleet_yaml('stretch_configuration_params.yaml')['robot']['batch_name'].lower() batch_name = hu.read_fleet_yaml('stretch_configuration_params.yaml')['robot']['batch_name'].lower()
else: else:
batch_name = hu.read_fleet_yaml('stretch_re1_factory_params.yaml')['robot']['batch_name'].lower() batch_name = hu.read_fleet_yaml('stretch_re1_factory_params.yaml')['robot']['batch_name'].lower()
cmd_cp_meshes = 'cp ~/catkin_ws/src/stretch_ros/stretch_description/batch/' + batch_name + '/meshes/*.STL ~/catkin_ws/src/stretch_ros/stretch_description/meshes'
cmd_cp_urdfs = 'cp ~/catkin_ws/src/stretch_ros/stretch_description/batch/' + batch_name + '/urdf/* ~/catkin_ws/src/stretch_ros/stretch_description/meshes'
batch_meshes_path = os.path.expanduser(
'~/catkin_ws/src/stretch_ros/stretch_description/batch/' + batch_name) + '/meshes/*.STL'
batch_urdfs_path = os.path.expanduser('~/catkin_ws/src/stretch_ros/stretch_description/batch/' + batch_name) + '/urdf/*.xacro'
meshes_path = os.path.expanduser('~/catkin_ws/src/stretch_ros/stretch_description/meshes')
urdfs_path = os.path.expanduser('~/catkin_ws/src/stretch_ros/stretch_description/urdf')
cmd_cp_meshes = 'cp {} {}'.format(batch_meshes_path, meshes_path)
cmd_cp_urdfs = 'cp {} {}'.format(batch_urdfs_path, urdfs_path)
print("Copying in Mesh files and URDF files from batch:" + batch_name) print("Copying in Mesh files and URDF files from batch:" + batch_name)
print(cmd_cp_meshes) print(cmd_cp_meshes)
os.system(cmd_cp_meshes)
run_cmd(cmd_cp_meshes)
print(cmd_cp_urdfs) print(cmd_cp_urdfs)
os.system(cmd_cp_urdfs)
run_cmd(cmd_cp_urdfs)

Loading…
Cancel
Save