Skip to content

Instantly share code, notes, and snippets.

@HemaZ
Created September 30, 2020 14:45
Show Gist options
  • Save HemaZ/1690ad3b60da4c3baebc68c355bec0f4 to your computer and use it in GitHub Desktop.
Save HemaZ/1690ad3b60da4c3baebc68c355bec0f4 to your computer and use it in GitHub Desktop.
import subprocess
import os
import time
import signal
class Prius:
def on_start(self):
front_camera = self.get_port_info("front_camera/image_raw")["topic"] # we wii use this to get Block id
x = self.get_property("x") # get x location form block's property
y = self.get_property("y") # get y location from block's property
workspace_path = os.path.join(self.get_property("ws_path"), "") # get the workspace path from the block's property
self.block_id = front_camera.split("/")[1] # get block id by splitting the topic name ex. ['','b12','front_camera','image_raw']
self.control_topic = self.get_port_info("prius")["topic"] # get the input port topic name
if not os.path.isdir(workspace_path + "devel"): # check if ROS workspace is not built
self.alert("Building ROS workspace", "INFO")
subprocess.run(
"cd {} && . /opt/ros/melodic/setup.sh && catkin_make".format(
workspace_path
),
shell=True,
)
subprocess.Popen(
"vglrun bash -c 'source {} && roslaunch car_demo spawn_prius.launch block_id:={} x:={} y:={} '".format(
workspace_path + "devel/setup.bash", self.block_id, x, y
),
shell=True,
) # run the launch file and pass the arguments block_id, x, y
self.relay_p = subprocess.Popen(
"rosrun topic_tools relay {} {}".format(
self.control_topic, "/" + self.block_id + "/prius"
),
shell=True,
) # create a topic realy to map input topic to block_id/prius topic which the robot is using for control
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment