Sunday, January 28, 2018

源型漏型输入



源型输入是电流从sensor流到PLC(PNP)
漏型是电流从PLC流到sensor(NPN)

in another words
源型输入是电流从com端流出!
漏型是电流从com端流入

电流的方向都是从正到负!


在接三线sensor时,output先与任意一个input terminal链接,如果是PNP型sensor,则common端要接到电源负极。如果是NPN型sensor,common端要接到电源正极。

Thursday, November 16, 2017

Allen Bradley and siemens IP configuration and IoT module settings

AB:
1. USE usb2RS232 cable to connect to the CPU. CPU is connected to Ethernet module, ControlNet module and device Net module.

2. Open RSlinx. Delete all previous drivers(if cannot delete just restart Rslinx while everything is disconnected)!!! Configure a driver called RS-232 DF1 drivers. Select correct COM and baud rate to establish the driver. Should be able to see all the above devices in RSwho under this driver. Then select the Ethernet module, right click to change the properties, where we can set the IP and subnet mask for the Ethernet module.

3. Still in RSlinx, configure a driver for Ethernet. The name of driver is "Ethernet devices". When configure it there will be a window pop out asking for the IP address, put the address you set in step 2 into station 0, click okay. Then all above devices on the same backplane will have the same IP address will show up in RSWho.

3. Open RSLOGIX5000, should be able to see the devices on the same chassis in WhoActive.


SIEMENS:
1. ALL IP SETTINGS CAN BE DONE IN TIA PORTAL as long as the PLC is connected with Ethernet to the computer(workstation).
2.open TIA portal, first create the project without a in-predefined device, then start device detection
3.after successfully detected of the device, go to the project tree and select "online & diagnostics", in the menu we have a lot of options such as assign IP address or formatting the SD card, etc...


For using the IoT module for siemens PLC:
1. for setting the IP address and subnet mask: please refer to IoT2000 setup in the google drive(miles.luo.xl@google.com). The firmware of IoT2000 is dumped to the SD card and then used in the IoT2040 module in my case. It works.....

2. For installing the node-red please refer to the PDF showing the steps(miles.luo.xl@google.com). One thing to note is that all installations should be with the internet connection of the IoT module! Installing the nodes for S7 communication and Azure IoT-hub then. Refer to the PDF or go to the website of node-red. If it somehow doesn't work just simply format the SD card in TIA portal!

The code to start node red in the IoT module's OS: node /usr/lib/node_modules/node-red/red &
Current flow is stored at /home/root/.node-red/ can ls and rm the undesired flow (the folder is invisible for WINscp)

3. Follow the setting in this video to set up a flow. S7 reading value------>construct a payload string in correct format------>upload to IoT using the Azure IoT hub node. Done! The thing is to correctly construct a payload string in the correct format.

{
  "deviceId": "testenode1",
  "key": "cw3nniq77BbjpOCDLqb7xEFTU509HeR6Ki1NwR20jj0=",
  "protocol": "amqp",
  "data": "{tem: 25, wind: 20}"
}


4. Use the flow in this link to register the device in IoT hub:https://flows.nodered.org/node/node-red-contrib-azure-iot-hub. After registering we will have a key to access the hub.

For using the IoT module with AB PLC:


Friday, September 15, 2017

行星系坐标变换 和 一些 OPENGL的感悟

这个例子是地球绕太阳,月亮同时绕地球的渲染

1.太阳为原点渲染,地球的坐标先平移,再绕原点y轴旋转渲染
2.麻烦的是月亮。月亮的坐标上传后也以原点为中心(big bang模式!opengl的模型上传之后,其局部坐标和世界坐标是重合的,后续的变换都是在世界坐标系中进行的!就像宇宙形成一样从中心大爆炸!)


    1)月亮变换第一种方法:先缩放,然后偏移(偏移距离是月亮距离原点(即太阳)的绝对距离),然后进行坐标系变换,将此时的坐标(在太阳坐标系中给出)变换到地球坐标系中去。由于地球的坐标系是在太阳坐标系的基础上,先旋转再平移得到的(注意两者都有!),所以构建两个view变换矩阵,一个是旋转,一个是平移,月亮的太阳坐标先乘以旋转再乘以平移,得到月亮在地球坐标系里的坐标。(最后为了render,还要将这个坐标变换回太阳坐标系去,同样乘以两个view矩阵,不过和第一步的是相反的方向)。总体是一个世界到local,做完旋转在回到世界的变换过程。

    2) 第二种方法,月亮的坐标先缩放,再偏移,不过此时的偏移量按照相对地球的距离进行。然后做旋转,此时月亮是围绕中心轴以相对地球的偏移在旋转(这些变换都是在太阳坐标系下进行的)。接下来将旋转之后的坐标变换到地球坐标系中去,同样需要一个旋转一个平移变换,得到月亮在地球坐标系的坐标。最后再用两个相反的矩阵将这个坐标变换会太阳坐标系用于render。整体上是一个先在世界坐标系做完旋转(注意此时的旋转半径是月亮相对地球的距离),变换到local坐标,然后再回到世界的过程。

上述变换和在hexapod设计中的坐标变换是类似的(将旋转平台的坐标变换到base坐标系中去,而base坐标系是由旋转坐标系先旋转再平移得到的,所以构建两个view变换矩阵来做变换)

要记住view变换(坐标系变换)和坐标变换之间的关系!

opengl glutPostRedisplay(void)

1用法编辑
void glutPostRedisplay(void);

2描述编辑

glutPostRedisplay 标记当前窗口需要重新绘制。通过glutMainLoop下一次循环时,窗口显示将被回调以重新显示窗口的正常面板。多次调用glutPostRedisplay,在下一个显示回调只产生单一的重新显示回调。
为了便于理解,用下面的例子[1]来说明:
假设有绘制代码:
glutDisplayFunc(display); // opengl drawing goes here
glutTimerFunc(30, drive, -1);// physics, movement equations here
glutMainLoop();
另外有代码如下:
void drive (int data)
{
glutTimerFunc(30, drive, -1);// call drive() again in 30 milliseconds
glutPostRedisplay();
}
如果有glutpostredisplay,mianloop运行的过程会像下面这样:
drive (-1);
display();
drive (-1);
display();
drive (-1);
display();
...
如果没有glutPostRedisplay,glutMainloop运行的过程会像下面这样:
drive (-1);
drive (-1);
drive (-1);
...




Tuesday, July 4, 2017

圆柱度 直线度 和直径公差关系推演


上述例子基于mcmaster的直线圆柱界面导轨数据: 直线度0.001", 直径公差-0.001". 可见该导轨的圆柱度公差还是有可能达到0.002"。

Sunday, July 2, 2017

数据结构与算法--fibonacci的动态规划解法



对比下面这个用一个数组来存储中间变量的方法:以下代码为JAVA:
  1.    /** 
  2.      * 自底向上包含"动态规划"思想的解法 
  3.      * @param n 
  4.      * @return 第n个斐波那契数 
  5.      */  
  6.     public static int downToTopReslove(int n) {  
  7.         if(n == 0) {  
  8.             return 0;  
  9.         } else if(n == 1 || n == 2) {  
  10.             return 1;  
  11.         } else {  
  12.             int[] fibonacciArray = new int[n+1]; //fibonacciArray[i]表示第i个斐波那契数  
  13.             fibonacciArray[0] = 0;  
  14.             fibonacciArray[1] = 1;  
  15.             fibonacciArray[2] = 1;  
  16.             for(int i=3;i<=n;i++) { //注意由于fibonacciArray[0]表示第0个元素,这里是i<=n,而不是i<n  
  17.                 fibonacciArray[i] = fibonacciArray[i-1] + fibonacciArray[i-2];  
  18.             }  
  19.               
  20.             return fibonacciArray[fibonacciArray.length-1];  
  21.         }  
  22.     }  

第一个算法只用了两个中间变量来存储中间值,每次值都会有变化,而第二个方法则是每个中间值都被存储在了对应的数组元素里。

上述两种算法都体现了动态规划的思想。