{ "cells": [ { "cell_type": "markdown", "id": "bbe6ec77", "metadata": {}, "source": [ "处理原始数据origin.csv" ] }, { "cell_type": "code", "execution_count": 1, "id": "e77e804a", "metadata": { "execution": { "iopub.execute_input": "2022-12-07T16:58:08.770045Z", "iopub.status.busy": "2022-12-07T16:58:08.769489Z", "iopub.status.idle": "2022-12-07T16:58:08.826735Z", "shell.execute_reply": "2022-12-07T16:58:08.825976Z" }, "origin_pos": 1, "tab": [ "pytorch" ] }, "outputs": [], "source": [ "import hashlib\n", "import os\n", "import tarfile\n", "import zipfile\n", "import requests\n", "import math\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "5f97aaa0", "metadata": { "execution": { "iopub.execute_input": "2022-12-07T16:58:08.849212Z", "iopub.status.busy": "2022-12-07T16:58:08.848803Z", "iopub.status.idle": "2022-12-07T16:58:11.308665Z", "shell.execute_reply": "2022-12-07T16:58:11.307847Z" }, "origin_pos": 8, "tab": [ "pytorch" ] }, "outputs": [], "source": [ "\n", "%matplotlib inline\n", "import pandas as pd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "将位姿数据拆分为6个属性" ] }, { "cell_type": "code", "execution_count": null, "id": "ebe45f59", "metadata": {}, "outputs": [], "source": [ "data = pd.read_csv(\"origin.csv\")\n", "data[\"TCP位姿\"] = data[\"TCP位姿\"].str.strip(\"[]\").str.split(\",\") \n", "# 使用apply(pd.Series)方法将列表展开为多列,并合并到原来的DataFrame对象中 \n", "data = data.join(data[\"TCP位姿\"].apply(pd.Series)) " ] }, { "cell_type": "markdown", "id": "6100a284", "metadata": {}, "source": [ "将时间转化为时间戳" ] }, { "cell_type": "code", "execution_count": null, "id": "7bb4fbce", "metadata": {}, "outputs": [], "source": [ "from datetime import datetime\n", " \n", "def toNum(x):\n", " datetime_object = datetime.strptime(x, '%Y/%m/%d %H:%M:%S')\n", " return datetime_object.timestamp()\n", " # return x.replace(\":\",\"\").replace(\"/\",\"\").replace(\" \",\"\")\n", "data[\"createTime\"]=data[\"创建时间\"].map(toNum)" ] }, { "cell_type": "markdown", "id": "5edec8a4", "metadata": {}, "source": [ "提取有用的属性" ] }, { "cell_type": "code", "execution_count": null, "id": "08d63378", "metadata": {}, "outputs": [], "source": [ "data1=data[[\"createTime\",0,1,2,3,4,5,\"焊接速度\",\"焊接电压\",\"焊接电流\"]]\n", "data1.head()\n", "data1.to_csv(\"pos_time_cvv.csv\",index=False)" ] }, { "cell_type": "markdown", "id": "574f3b97", "metadata": {}, "source": [ "删除冗余和异常数据" ] }, { "cell_type": "code", "execution_count": 16, "id": "fe01601c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(790966, 10)\n", "(185143, 10)\n" ] } ], "source": [ "data=pd.read_csv(\"pos_time_cvv.csv\")\n", "print(data.shape)\n", "# data=data.drop_duplicates([\"0\",\"1\",\"2\",\"焊接电流\",\"焊接电压\"],keep='first')\n", "toDeleteList=[]\n", "x=data[\"1\"]\n", "y=data[\"2\"]\n", "z=data[\"3\"]\n", "v=data[\"焊接电压\"]\n", "c=data[\"焊接电流\"]\n", "time=data[\"createTime\"]\n", "x1=[]\n", "y1=[]\n", "z1=[]\n", "v1=[]\n", "c1=[]\n", "t1=[]\n", "count=0\n", "lastTime=time[0]\n", "lastV=0\n", "lastC=0\n", "lastX=0\n", "lastY=0\n", "lastZ=0\n", "thisTime=0\n", "colors=['b', 'g', 'r', 'c', 'm', 'y', 'k', 'w']\n", "colorCnt=0\n", "for tup in zip(x,y,z,time,v,c):\n", " # print(tup,type(tup[1:]))\n", "\n", " thisTime=tup[3]\n", " if (tup[4]==lastV and tup[5]==lastC)or\\\n", " (lastX==tup[0] and lastY==tup[1] and lastZ==tup[2])or tup[5]==400 or\\\n", " abs(lastC-tup[5])>30:\n", " # print(count)\n", " colorCnt+=1\n", " toDeleteList.append(count)\n", " \n", " \n", " \n", " # print(len(x1))\n", " \n", " x1=[]\n", " y1=[]\n", " z1=[]\n", " v1=[]\n", " c1=[]\n", " t1=[]\n", " count+=1 \n", " lastV=tup[4]\n", " lastC=tup[5]\n", " lastX=tup[0]\n", " lastY=tup[1]\n", " lastZ=tup[2]\n", " lastTime=thisTime\n", "data=data.drop(toDeleteList)\n", "print(data.values.shape)\n", "data.to_csv(\"delete_same_and_sharp.csv\",index=False)" ] }, { "cell_type": "markdown", "id": "92aba770", "metadata": {}, "source": [ "提取line(因为轨迹是一条条的线,所以可以把轨迹投影到xoy平面)" ] }, { "cell_type": "code", "execution_count": 53, "id": "b02274bc", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(183427, 10)\n", "(1320, 10)\n" ] } ], "source": [ "\n", "# data=data.drop_duplicates([\"0\",\"1\",\"2\",\"焊接电流\",\"焊接电压\"],keep='first')\n", "def dis(x1,y1,x2,y2):\n", " return math.sqrt((x1-x2)**2+(y1-y2)**2)\n", "data=pd.read_csv(\"delete_same_and_sharp3.csv\")\n", "x=data[\"1\"]\n", "y=data[\"2\"]\n", "z=data[\"3\"]\n", "v=data[\"焊接电压\"]\n", "c=data[\"焊接电流\"]\n", "time=data[\"createTime\"]\n", "toDeleteList=[]\n", "x1=[]\n", "y1=[]\n", "z1=[]\n", "v1=[]\n", "c1=[]\n", "t1=[]\n", "count=0\n", "lastTime=0\n", "lastV=0\n", "lastC=0\n", "lastX=0\n", "lastY=0\n", "lastZ=0\n", "thisTime=0\n", "colors=['b', 'g', 'r', 'c', 'm', 'y', 'k', 'w']\n", "colorCnt=0\n", "for tup in zip(x,y,z,time,v,c):\n", " # print(tup,type(tup[1:]))\n", "\n", " thisTime=tup[3]\n", " if dis(lastY,lastZ,tup[1],tup[2])<1:\n", " # print(count)\n", " colorCnt+=1\n", " toDeleteList.append(count)\n", " \n", " \n", " \n", " # print(len(x1))\n", "\n", " x1=[]\n", " y1=[]\n", " z1=[]\n", " v1=[]\n", " c1=[]\n", " t1=[]\n", " count+=1 \n", " lastV=tup[4]\n", " lastC=tup[5]\n", " lastX=tup[0]\n", " lastY=tup[1]\n", " lastZ=tup[2]\n", " lastTime=thisTime\n", "# print(toDeleteList)\n", "print(data.shape)\n", "data=data.drop(toDeleteList)\n", "# print(data['createTime'])\n", "\n", "data.to_csv(\"line.csv\",index=False)\n", "\n", "print(data.shape)\n", "# data.to_csv(\"delete_same_and_sharp7.csv\",index=False)" ] }, { "cell_type": "markdown", "id": "b937fa76", "metadata": {}, "source": [ "合并相近的line(离得太近的合并到一起,减少点的数量)" ] }, { "cell_type": "code", "execution_count": 54, "id": "37a9a5b7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(1320, 10)\n", "(872, 10)\n" ] } ], "source": [ "def dis(x1,y1,x2,y2):\n", " return math.sqrt((x1-x2)**2+(y1-y2)**2)\n", "data=pd.read_csv(\"line.csv\")\n", "x=data[\"1\"]\n", "y=data[\"2\"]\n", "z=data[\"3\"]\n", "v=data[\"焊接电压\"]\n", "c=data[\"焊接电流\"]\n", "time=data[\"createTime\"]\n", "toDeleteList=[]\n", "x1=[]\n", "y1=[]\n", "z1=[]\n", "v1=[]\n", "c1=[]\n", "t1=[]\n", "count=0\n", "lastTime=0\n", "lastV=0\n", "lastC=0\n", "lastX=0\n", "lastY=0\n", "lastZ=0\n", "thisTime=0\n", "colors=['b', 'g', 'r', 'c', 'm', 'y', 'k', 'w']\n", "colorCnt=0\n", "for tup in zip(x,y,z,time,v,c):\n", " # print(tup,type(tup[1:]))\n", "\n", " thisTime=tup[3]\n", " if abs(lastTime-tup[3])<100:\n", " # print(count)\n", " colorCnt+=1\n", " toDeleteList.append(count)\n", " \n", " \n", " \n", " # print(len(x1))\n", "\n", " x1=[]\n", " y1=[]\n", " z1=[]\n", " v1=[]\n", " c1=[]\n", " t1=[]\n", " count+=1 \n", " lastV=tup[4]\n", " lastC=tup[5]\n", " lastX=tup[0]\n", " lastY=tup[1]\n", " lastZ=tup[2]\n", " lastTime=thisTime\n", "# print(toDeleteList)\n", "print(data.shape)\n", "data=data.drop(toDeleteList)\n", "# print(data['createTime'])\n", "\n", "data.to_csv(\"line0.csv\",index=False)\n", "\n", "print(data.shape)" ] }, { "cell_type": "code", "execution_count": 9, "id": "96afb190", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
创建时间在线驱动已打开操作模式当前程序号当前程序步TCP位姿焊接电流驱动打开时间停止采集日期...焊接状态.1保护气流量焊接速度012345createTime
02022/8/1 8:08:38TrueTrue1.0NaN0.0.0[-3.101456, -622.703380, -527.500837, -0.50521...329.0428064781936442022-8-2 0:47:18.003...False0.0293880.0-3.101456-622.703380-527.500837-0.505214108.646219-4.1071301.659313e+09
12022/8/1 8:08:39TrueTrue1.0NaN0.0.0[-3.101456, -622.703380, -527.500837, -0.50521...329.0428064781936442022-8-2 0:47:18.003...False0.0293880.0-3.101456-622.703380-527.500837-0.505214108.646219-4.1071301.659313e+09
22022/8/1 8:08:40TrueTrue1.0NaN0.0.0[-3.101456, -622.703380, -527.500837, -0.50521...329.0428064781936442022-8-2 0:47:18.003...False0.0293880.0-3.101456-622.703380-527.500837-0.505214108.646219-4.1071301.659313e+09
32022/8/1 8:08:41TrueTrue1.0NaN0.0.0[-3.101456, -622.703380, -527.500837, -0.50521...329.0428064781936442022-8-2 0:47:18.003...False0.0293880.0-3.101456-622.703380-527.500837-0.505214108.646219-4.1071301.659313e+09
42022/8/1 8:08:42TrueTrue1.0NaN0.0.0[-3.101456, -622.703380, -527.500837, -0.50521...329.0428064781936442022-8-2 0:47:18.003...False0.0293880.0-3.101456-622.703380-527.500837-0.505214108.646219-4.1071301.659313e+09
\n", "

5 rows × 37 columns

\n", "
" ], "text/plain": [ " 创建时间 在线 驱动已打开 操作模式 当前程序号 当前程序步 \\\n", "0 2022/8/1 8:08:38 True True 1.0 NaN 0.0.0 \n", "1 2022/8/1 8:08:39 True True 1.0 NaN 0.0.0 \n", "2 2022/8/1 8:08:40 True True 1.0 NaN 0.0.0 \n", "3 2022/8/1 8:08:41 True True 1.0 NaN 0.0.0 \n", "4 2022/8/1 8:08:42 True True 1.0 NaN 0.0.0 \n", "\n", " TCP位姿 焊接电流 驱动打开时间 \\\n", "0 [-3.101456, -622.703380, -527.500837, -0.50521... 329.0 42806478193644 \n", "1 [-3.101456, -622.703380, -527.500837, -0.50521... 329.0 42806478193644 \n", "2 [-3.101456, -622.703380, -527.500837, -0.50521... 329.0 42806478193644 \n", "3 [-3.101456, -622.703380, -527.500837, -0.50521... 329.0 42806478193644 \n", "4 [-3.101456, -622.703380, -527.500837, -0.50521... 329.0 42806478193644 \n", "\n", " 停止采集日期 ... 焊接状态.1 保护气流量 焊接速度 0 1 \\\n", "0 2022-8-2 0:47:18.003 ... False 0.029388 0.0 -3.101456 -622.703380 \n", "1 2022-8-2 0:47:18.003 ... False 0.029388 0.0 -3.101456 -622.703380 \n", "2 2022-8-2 0:47:18.003 ... False 0.029388 0.0 -3.101456 -622.703380 \n", "3 2022-8-2 0:47:18.003 ... False 0.029388 0.0 -3.101456 -622.703380 \n", "4 2022-8-2 0:47:18.003 ... False 0.029388 0.0 -3.101456 -622.703380 \n", "\n", " 2 3 4 5 createTime \n", "0 -527.500837 -0.505214 108.646219 -4.107130 1.659313e+09 \n", "1 -527.500837 -0.505214 108.646219 -4.107130 1.659313e+09 \n", "2 -527.500837 -0.505214 108.646219 -4.107130 1.659313e+09 \n", "3 -527.500837 -0.505214 108.646219 -4.107130 1.659313e+09 \n", "4 -527.500837 -0.505214 108.646219 -4.107130 1.659313e+09 \n", "\n", "[5 rows x 37 columns]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# print(data.iloc[[0,1,2], :])\n", "data.head()\n", "# data.to_csv(\"origin_TimePos.csv\",index=False)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.16 ('torch_py3.9')", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.16" }, "vscode": { "interpreter": { "hash": "2c93e8e09754cf1cd40b55c7c8fefeaff6ac58d6a85dd394fdad2eae466f5690" } } }, "nbformat": 4, "nbformat_minor": 5 }