Launch into space

火箭发射数据分析与可视化
本文通过对固定格式文件的解析,详细分析了火箭发射日期、成功概率、年份发射比例及一周内各工作日的发射频率,并通过图表展示了数据洞察。
I saw a link to a list with all rocket launches into space the other day. This post contains some plots concerning day of launch made from that.

Data

Data is a fixed format file with eleven columns. Reading fixed format is not very difficult, however, it requires a bit of preparation. In this case, the first row contains a description of the columns, the second a number of '#'signs to denote the start of the columns. I found it most logical to first get the column widths, use these to create the variable names and then read the data. There is an interesting detail, the first two rows have '#' as first character, read.fwf has this as default comment character and skips them.
library(dplyr)
library(ggplot2)
library(lme4)
r1 <- readLines('launchlog.txt')
colwidth  <- gregexpr('#',r1[2])[[1]] %>%
    c(.,max(nchar(r1))) %>%
    diff(.)

cols <- read.fwf(textConnection(r1[1]),
        widths=colwidth,
        header=FALSE,
        comment.char='@') %>%
    unlist(.) %>%
    make.names(.) %>%
    gsub('\.+$','',.) # remove extra . at end of string

r2 <- read.fwf('launchlog.txt',
    widths=colwidth,
    col.names=cols) 
Some launches contain more than one pay load. These are represented by rows containing just pay load information. These are removed by removing all records without a success value. In addition, a date variable is created using the launch date. Extra spaces, a consequence of the fixed input format, are removed from the suc variable.
r3 <- filter(r2,!is.na(Suc))
Sys.setlocale(category = "LC_TIME", locale = "C")
r3$Launch.Date..UTC[1:3]
r3$Date <- as.Date(r3$Launch.Date..UTC,format='%Y %b %d')
levels(r3$Suc) <- gsub(' *','',levels(r3$Suc))

Plots

Preparation
Since I wanted proportion of days with a launch, I created a few extra data frames. alldays contains all dates. monthorder and wdorder provide additional variables intended to arrange the months and week days in a reasonable order.
alldays <- data.frame(
    Date=seq(
        min(r3$Date),
        max(r3$Date) ,
        by=1 ))

monthorder <- alldays %>%
    mutate(.,
        month=months(Date),
        mn=format(Date,'%m')) %>%
    select(.,month,mn) %>%
    unique(.) %>%
    arrange(.,mn)

wdorder <- alldays %>%
    mutate(.,
        wd=weekdays(Date),
        wdn=format(Date,'%u')) %>%
    select(.,wd,wdn) %>%    
    unique(.) %>%
    arrange(.,wdn)
By month
January seems to get least launches. On the other hand December most. I wonder if that is publicity seeking in December of the well know January 1st deadline.
By weekdays
As expected, middle of the week gets most launches. The lower value for Monday than Saturday suggests the day before a launch is just as busy as the day of launch itself.
numlawd <-    mutate(r3,
        wd =factor(weekdays(Date),levels=wdorder$wd)) %>%
    xtabs( ~ wd,.) %>%
    as.data.frame(.) %>%
    rename(.,Occur=Freq)
numwd <-    mutate(alldays,
        wd =factor(weekdays(Date),levels=wdorder$wd)) %>%
    xtabs( ~ wd,.) %>%
    as.data.frame(.) %>%
    rename(.,NM=Freq)
propbwd <- merge(numlawd,numwd) %>%
    mutate(prop=Occur/NM)
qplot(y=prop,x= wd,data=propbwd) +
    ylab('Proportion') +
    xlab('Day of Week') +
    ggtitle('Proportion Week Days with Launch') +
    coord_flip()
By year
For years I have made a split between success and fail. It is also the most interesting of plots. Proportion launches per day increases quickly in the first years, as does the chance of a success. By mid eighties the launches decrease, only to pick up in the new millennium. The end of the space race is not visible in the number of launches, but seems to coincide with less failed launches. 
numlayr <- mutate(r3,year =factor(format(Date,'%Y'))) %>%
    xtabs( ~ year + Suc,.) %>%
    as.data.frame(.) %>%
    rename(.,Occur=Freq)
numyr <-    mutate(alldays,year =factor(format(Date,'%Y'))) %>%
    xtabs( ~ year,.) %>%
    as.data.frame(.) %>%
    rename(.,NM=Freq)
propyr <- merge(numlayr,numyr) %>%
    mutate(prop=Occur/NM,
        Year=as.numeric(levels(year))[year])
qplot(y=prop,x= Year,colour=Suc,data=propyr) +
    ylab('Proportion') +
    xlab('Year') +
    ggtitle('Proportion Days with Launch') +
    scale_colour_discrete(name='Success')

Most busy day?
Once there were four launches on a day.
r3 %>% xtabs(~factor(Date,levels=as.character(alldays$Date)),.) %>%
    as.data.frame(.) %>%
    rename(.,Nlaunch=Freq) %>%
    xtabs(~Nlaunch,.) %>%
    as.data.frame(.) 
  Nlaunch  Freq
1       0 16154
2       1  4224
3       2   562
4       3    44
5       4     1
ncut@ubuntu:~$ sudo apt-get install ros-kinetic-usb-cam [sudo] password for ncut: Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package ros-kinetic-usb-cam ncut@ubuntu:~$ cd catkin_ws/src ncut@ubuntu:~/catkin_ws/src$ git clone http://github.com/bosch-ros-pkg/usb_cam.git Cloning into 'usb_cam'... warning: redirecting to https://github.com/bosch-ros-pkg/usb_cam.git/ remote: Enumerating objects: 3476, done. remote: Counting objects: 100% (776/776), done. remote: Compressing objects: 100% (281/281), done. remote: Total 3476 (delta 576), reused 520 (delta 495), pack-reused 2700 (from 4) Receiving objects: 100% (3476/3476), 1.92 MiB | 458.00 KiB/s, done. Resolving deltas: 100% (1625/1625), done. ncut@ubuntu:~/catkin_ws/src$ cd ~/catkin_ws ncut@ubuntu:~/catkin_ws$ catkin_make Base path: /home/ncut/catkin_ws Source space: /home/ncut/catkin_ws/src Build space: /home/ncut/catkin_ws/build Devel space: /home/ncut/catkin_ws/devel Install space: /home/ncut/catkin_ws/install #### #### Running command: "cmake /home/ncut/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/ncut/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/ncut/catkin_ws/install -G Unix Makefiles" in "/home/ncut/catkin_ws/build" #### -- Using CATKIN_DEVEL_PREFIX: /home/ncut/catkin_ws/devel -- Using CMAKE_PREFIX_PATH: /home/ncut/catkin_ws/devel;/home/ncut/robot_ws/devel;/opt/ros/melodic -- This workspace overlays: /home/ncut/catkin_ws/devel;/home/ncut/robot_ws/devel;/opt/ros/melodic -- Found PythonInterp: /usr/bin/python2 (found suitable version "2.7.17", minimum required is "2") -- Using PYTHON_EXECUTABLE: /usr/bin/python2 -- Using Debian Python package layout -- Using empy: /usr/bin/empy -- Using CATKIN_ENABLE_TESTING: ON -- Call enable_testing() -- Using CATKIN_TEST_RESULTS_DIR: /home/ncut/catkin_ws/build/test_results -- Found gtest sources under '/usr/src/googletest': gtests will be built -- Found gmock sources under '/usr/src/googletest': gmock will
03-30
<think>嗯,用户问的是如何在ROS Kinetic下成功安装usb_cam包以及处理相关的依赖问题。首先,我需要回忆一下ROS Kinetic的版本对应的Ubuntu版本。ROS Kinetic通常对应Ubuntu 16.04,而用户提供的引用中提到了indigo,但那是更旧的版本,对应Ubuntu 14.04。所以用户可能混淆了版本,需要指出正确的安装方法。 根据引用[3]和[4],usb_cam的官方仓库已经迁移到ros-drivers组织下,所以正确的下载链接应该是https://github.com/ros-drivers/usb_cam。用户需要先将这个仓库克隆到自己的catkin工作空间的src目录下,然后使用catkin_make来编译。不过要确保ROS Kinetic的依赖项都安装好了。 然后,引用[1]提到了安装依赖包时要注意ROS版本。用户可能需要安装针对Kinetic的依赖,比如ros-kinetic-usb-cam,而不是indigo。所以需要提醒用户替换版本号。此外,可能还需要安装其他依赖,比如相机相关的驱动包,比如libuvc等。 另外,引用[5]提到如果摄像头页面不显示,可能需要修改launch文件中的设备节点,比如将/dev/video0改为正确的设备号。这可能也是用户安装后遇到的问题之一,需要包含在解决方案中。 步骤应该是先安装依赖,然后下载正确的usb_cam包,编译,处理可能的错误,比如缺少依赖时的解决方法,比如使用rosdep来安装缺少的包。最后测试运行,并处理常见问题,比如权限问题或者设备号不正确。 需要检查用户是否已经创建了catkin工作空间,如果没有的话,需要指导他们创建。另外,安装完成后,运行launch文件时可能需要摄像头权限,提醒用户使用sudo或者将用户加入video组。 总结下来,安装步骤包括:1.安装系统依赖;2.下载源码到工作空间;3.编译;4.处理可能的依赖错误;5.修改launch文件中的设备路径;6.测试运行。同时,常见问题要涵盖编译错误和摄像头无法显示的情况。</think>### 解决ROS Kinetic安装usb_cam包的步骤 #### 1. **安装系统依赖** - 首先安装`libuvc`和`v4l-utils`以支持USB摄像头硬件: ```bash sudo apt-get install libuvc-dev v4l-utils ``` - 安装ROS Kinetic版本的`usb_cam`依赖包(注意替换版本号): ```bash sudo apt-get install ros-kinetic-image-transport ros-kinetic-camera-info-manager ``` #### 2. **下载并编译usb_cam包** - 进入工作空间的`src`目录,克隆官方仓库: ```bash cd ~/catkin_ws/src git clone https://github.com/ros-drivers/usb_cam.git ``` - 返回工作空间根目录编译: ```bash cd ~/catkin_ws catkin_make ``` - 若编译报错缺少依赖,运行以下命令自动安装: ```bash rosdep install --from-paths src --ignore-src -y ``` #### 3. **修改launch文件参数** - 打开`usb_cam-test.launch`文件,检查设备路径是否为实际摄像头节点(如`/dev/video0`): ```xml <param name="video_device" value="/dev/video0" /> ``` #### 4. **测试运行** - 启动摄像头节点: ```bash roslaunch usb_cam usb_cam-test.launch ``` - 若提示权限不足,执行: ```bash sudo chmod 777 /dev/video0 ``` #### 常见问题处理 - **编译失败**:若出现`catkin_make`报错,检查ROS环境变量是否生效(`source /opt/ros/kinetic/setup.bash`)[^3][^4]。 - **摄像头无画面**:确认摄像头是否被其他程序占用,或尝试更换`video_device`的端口号[^5]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值