17 """General utility functions."""
27 def find_os_processes(name: str) -> list[tuple[str, str]]:
28 """Find all the processes that are running gz sim."""
29 ps_output = subprocess.check_output([
'ps',
'aux'], text=
True)
30 ps_lines = ps_output.split(
'\n')
34 columns = line.split()
36 command =
' '.join(columns[10:])
37 if command.startswith(name):
38 gz_sim_processes.append((pid, command))
39 return gz_sim_processes
42 def kill_process(pid: str) ->
None:
43 """Kill a process with a given PID."""
45 os.kill(int(pid), signal.SIGKILL)
46 print(f
'Successfully killed process with PID: {pid}')
47 except Exception
as e:
48 print(f
'Failed to kill process with PID: {pid}. Error: {e}')
51 def kill_os_processes(name: str) ->
None:
52 """Kill all processes that are running with name."""
53 processes = find_os_processes(name)
55 for pid, _
in processes:
58 print(f
'No processes found starting with {name}')
61 def euler_to_quaternion(
62 roll: float = 0.0, pitch: float = 0.0,
63 yaw: float = 0.0) -> Quaternion:
64 """Convert euler angles to quaternion."""
65 cy = math.cos(yaw * 0.5)
66 sy = math.sin(yaw * 0.5)
67 cp = math.cos(pitch * 0.5)
68 sp = math.sin(pitch * 0.5)
69 cr = math.cos(roll * 0.5)
70 sr = math.sin(roll * 0.5)
73 q.w = cr * cp * cy + sr * sp * sy
74 q.x = sr * cp * cy - cr * sp * sy
75 q.y = cr * sp * cy + sr * cp * sy
76 q.z = cr * cp * sy - sr * sp * cy