2 The snapshot command creates a zip file of relevant robot debug info. 4 Copyright 2016-2019 Fetch Robotics Inc. 5 Authors: Aaron Blasdel, Eric Relson 14 from ..util
import ssh, add_robot
16 name =
"debug-snapshot" 17 help_text =
"Take a debug snapshot of a running robot" 19 snapshot_version =
"0.0.2" 21 fileroot =
"debug_snapshot" 22 fileroot =
'_' + fileroot +
'_' 27 rosbash =
'source /opt/ros/melodic/setup.bash;' 28 devnull = open(os.devnull,
'w+')
30 topics = [
"/robot_state",
36 commands = {
"dpkg_fetch":
"COLUMNS=200 dpkg -l ros-melodic-fetch-*",
37 "dpkg_ros":
"COLUMNS=200 dpkg -l ros-melodic-*",
38 "dpkg_all":
"COLUMNS=200 dpkg -l",
41 "roswtf": rosbash +
"roswtf",
42 "rosnode_list": rosbash +
"rosnode list",
43 "rostopic_list": rosbash +
"rostopic list",
44 "rossrv_list": rosbash +
"rosservice list",
45 "rosparam_list": rosbash +
"rosparam list",
46 "rosparam_dump": rosbash +
"rosparam get /",
48 "syslog":
"cat /var/log/syslog",
50 "meminfo":
"cat /proc/meminfo",
51 "ip_route":
"ip route",
52 "ifconfig":
"ifconfig -a",
53 "iwconfig":
"iwconfig",
54 "network_interfaces":
"cat /etc/network/interfaces",
55 "netplan_full":
"cat /etc/netplan/01-network-manager-all.yaml /etc/netplan/99-fetch-ethernet.yaml",
56 "hosts":
"cat /etc/hosts",
58 "roscore.service":
"cat /lib/systemd/system/roscore.service",
59 "roscore.service_status":
"service roscore status",
60 "robot.service":
"cat /lib/systemd/system/robot.service",
61 "robot.service_status":
"service robot status",
62 "robot.journalctl":
"journalctl -u robot",
63 "ps3joy.service":
"cat /lib/systemd/system/ps3joy.service",
64 "ps3joy.service_status":
"service ps3joy status",
65 "ps4joy.service":
"cat /lib/systemd/system/ps4joy.service",
66 "ps4joy.service_status":
"service ps4joy status",
67 "read_board_charger": rosbash +
"rosrun fetch_drivers read_board 0x3f",
68 "read_board_mainboard": rosbash +
"rosrun fetch_drivers read_board 0x00",
69 "read_board_wheel_left": rosbash +
"rosrun fetch_drivers read_board 0x11",
70 "read_board_wheel_right": rosbash +
"rosrun fetch_drivers read_board 0x12",
71 "read_board_gripper": rosbash +
"rosrun fetch_drivers read_board 0x80",
72 "battery_state": rosbash +
"rostopic echo -n 1 /battery_state",
73 "robot_state": rosbash +
"rostopic echo -n 1 /robot_state",
80 sudostr =
"echo %s | sudo -S " % args.fetch_password[-1]
82 commands.update({
"robot_log":sudostr +
"cat /var/log/ros/robot.log"})
84 print(
'Running debug snapshot tool.')
85 dirpath = tempfile.mkdtemp()
88 bag_process = [
'rosbag',
'record',
'-q',
'--duration=10',
'-j',
89 '-O', bagname] + topics
90 bag = subprocess.Popen(bag_process, cwd=dirpath, stdout=devnull)
93 with open(dirpath +
'/version.txt',
'w')
as version_file:
94 version_file.write(snapshot_version)
97 for key, value
in commands.iteritems():
98 print(
"Creating '%s.txt'." % key)
99 ssh(
'fetch', args.robot, value, fname=dirpath +
'/' + key,
100 password=args.fetch_password[-1])
102 print(
'Waiting for data gathering to complete')
108 timestr = datetime.datetime.now().strftime(
"%Y-%m-%d-%H-%M-%S")
109 filename = args.robot + fileroot + timestr +
'.zip' 111 print(
'Data gathering complete creating %s' % filename)
112 proc = subprocess.Popen([
"zip",
"-r", filename, dirpath],
118 shutil.rmtree(dirpath)
120 if proc.returncode == 0:
121 print(
"Created %s" % filename)
123 print(
"ERROR: failed to zip directory: %s" % dirpath)
127 "--fetch-password", nargs=
"?", action=
"append", default=[
"robotics"],
128 help=
"Password for the fetch account (or blank to prompt)"