In [1]:
import matplotlib.pyplot as plt
import rosbag_pandas
%matplotlib inline
In [10]:
rosbag_pandas.get_topics(rosbag_pandas.get_bag_info("bagfiles/2017-01-10-23-30-49.bigbag"))
Out[10]:
Potentially useful:
navdata state is important.
In [262]:
df0.ardrone_odometry__twist_twist_linear_x.plot()
Out[262]:
In [261]:
df0.ardrone_navdata__vx.plot()
Out[261]:
In [254]:
df0.ardrone_navdata__state.plot()
Out[254]:
In [237]:
plt.plot(range(len(df0)), df0.ardrone_navdata__az)
plt.plot(range(len(df0)), df0.ardrone_imu__linear_acceleration_z/10)
Out[237]:
In [35]:
df0 = rosbag_pandas.bag_to_dataframe("bagfiles/2017-01-10-23-30-49.bigbag", include=[
"/ardrone/ground_pose", "/ardrone/imu", "/ardrone/mag", "/ardrone/navdata",
"/ardrone/odometry", "/ardrone/past_pose", "/ardrone/pose", "/ardrone/tracked"])
In [36]:
df0.columns
Out[36]:
In [37]:
df0.plot.scatter("ardrone_odometry__pose_pose_position_x", "ardrone_odometry__pose_pose_position_y", c=df0.ardrone_odometry__pose_pose_position_z)
df0.plot.scatter("ardrone_pose__pose_position_x", "ardrone_pose__pose_position_y", c=df0.ardrone_pose__pose_position_z)
Out[37]:
In [38]:
df0.plot.scatter("ardrone_odometry__pose_pose_position_x", "ardrone_odometry__pose_pose_position_y", c=df0.ardrone_tracked__data)
Out[38]:
In [40]:
df0.tail()
Out[40]:
In [42]:
df0.fillna(method="pad", inplace=True)
df0.tail()
Out[42]:
In [44]:
df0.fillna(method="backfill", inplace=True)
df0.head()
Out[44]:
In [45]:
len(df0)
Out[45]:
In [47]:
df0.plot.scatter("ardrone_odometry__pose_pose_position_x", "ardrone_odometry__pose_pose_position_y")
Out[47]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [41]:
df1 = rosbag_pandas.bag_to_dataframe("bagfiles/2017-01-10-23-30-49.bigbag", include="/ardrone/pose")
df1.columns = ["d", "a", "b", "c", "x", "y", "z"]
df1.head()
Out[41]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
df2 = rosbag_pandas.bag_to_dataframe("bagfiles/2017-01-10-23-34-26.bigbag", include="/ardrone/pose")
df2.columns = ["d", "a", "b", "c", "x", "y", "z"]
df2.head()
In [62]:
from collections import namedtuple
Coords = namedtuple("Coords", "x y")
In [63]:
def load_bag(bagfile, topics="/ardrone/pose"):
return rosbag_pandas.bag_to_dataframe(bagfile, include=topics)
def load_pose(bagfile):
df = load_bag(bagfile)
df.columns = ["d", "a", "b", "c", "x", "y", "z"]
return df
In [82]:
df0.plot.scatter("ardrone_ground_pose__x", "ardrone_ground_pose__y", c=df0.index)
Out[82]:
In [281]:
def plot_xy(df, x="x", y="y", s="z", c=None, cmap="viridis", target_coords=(Coords(-1, 3.6), Coords(-2, 1.6)), target_color="r"):
"""
Coords in real frame. +x is towards doors, +y is away from table.
"""
if c is None:
c = df.index
if cmap is None:
cmap = "viridis_r"
else:
c = df[c]
if cmap is None:
cmap = "viridis"
p_init = Coords(df[x][0], df[y][0])
plt.scatter(-df[x], -df[y], s=df[s]*25, c=c, cmap=cmap)
plt.colorbar()
plt.scatter(-p_init.x, -p_init.y, c=target_color)
for coord in target_coords:
plt.scatter(-(p_init.x - coord.x), -(p_init.y - coord.y), c=target_color)
plt.axis("equal")
In [355]:
def plot_xy_if(df, df_if, x="x", y="y", s=None, c=None, cmap=None, cmap_if="gray", alpha=0.002,
target_coords=(Coords(-1, 3.6), Coords(-2, 1.6)), target_color="r"):
"""
Coords in real frame. +x is towards doors, +y is away from table.
"""
if s is None:
s = s_if = None
else:
s_if = df_if[s]*25
s = df[s]*25
if c is None:
c_if = df_if.index
c = df.index
if cmap is None:
cmap = "viridis_r"
else:
c_if = df_if[c]
c = df[c]
if cmap is None:
cmap = "viridis"
p_init = Coords(df[x][0], df[y][0])
plt.scatter(-df[x],
-df[y],
s=s,
c=c, cmap=cmap_if, alpha=alpha)
plt.scatter(-df_if[x],
-df_if[y],
s=s_if,
c=c_if, cmap=cmap)
plt.colorbar()
plt.scatter(-p_init.x, -p_init.y, c=target_color)
for coord in target_coords:
plt.scatter(-(p_init.x - coord.x), -(p_init.y - coord.y), c=target_color)
plt.axis("equal")
In [356]:
plot_xy_if(df0, df0[df0.ardrone_navdata__state == 4], "ardrone_pose__pose_position_x", "ardrone_pose__pose_position_y",
s="ardrone_pose__pose_position_z", c="ardrone_pose__pose_position_z", alpha = 0.002)
In [352]:
plot_xy_if(df0, df0[df0.ardrone_navdata__state == 4], "ardrone_pose__pose_position_x", "ardrone_pose__pose_position_y",
c="ardrone_pose__pose_position_z", alpha = 0)
In [265]:
plot_xy(df0, "ardrone_odometry__pose_pose_position_x", "ardrone_odometry__pose_pose_position_y",
s="ardrone_odometry__pose_pose_position_z")
In [250]:
df0.ardrone_past_pose__pose_position_x.plot()
df0.ardrone_pose__pose_position_x.plot()
Out[250]:
In [251]:
df0.ardrone_past_pose__pose_position_y.plot()
df0.ardrone_pose__pose_position_y.plot()
Out[251]:
In [252]:
df0.ardrone_past_pose__pose_position_z.plot()
df0.ardrone_pose__pose_position_z.plot()
Out[252]:
In [123]:
plot_xy(df2)
In [47]:
dfnd = load_bag("2017-01-10-23-30-49.bag", topics="/ardrone/navdata")
In [59]:
dfnd.columns = "altd ax ay az batt magX magY magZ motor1 motor2 motor3 motor4 pressure rotX rotY rotZ state tags_count temp tm vx vy vz wind_angle wind_comp_angle wind_speed".split()
dfnd.columns
Out[59]:
In [63]:
plt.plot(dfnd.index, dfnd.altd)
plt.plot(df1.index, df1.z*1000)
Out[63]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: