2014年6月26日 星期四

Mechanical Experiment Improvement

有幸為母校成大機械系設計一堂機械工程實驗課程 (還有幸今天可以打中文XD)

這堂課的設計目標是因為目前開源硬體非常流行(像是Arduino、Raspberry Pi),售價不斷下降時效能卻大幅提升。我想利用Open-Source的軟體硬體,製作在機械工程中非常重要的PID控制器。


上課的流程是這樣的

在硬體方面,系統架構如下
(實作時的紀錄可以參考: 之前)

最後冠冕堂晃的說


在這堂課程的基礎上,日後可以設計小型的Term Project,利用PID控制馬達來達成應用,像是倒單擺的實踐或是輪型機器人的精準控制等等。


本實驗的核心精神在於利用開源的軟體以及硬體,來實作課程中學到的理論,並且解決其中的問題,讓課堂的學習以及實驗課的操作相輔相成,訓練出實作與理論兼具的機械工程師。




2014年6月23日 星期一

Dillon - Thirteen Thirtyfive

Pretty like this song




Strongest taste
loudest drop
head is filled
the thought, unlocked

you'd be thirteen
i'd be thirty-five
gone to find a place for us to hide


be together but alone
as the need for it has grown

a cave or a shed
a car or a bed
a hole in the ground
or a burial mound
a bush or a tree
or the aegean sea will do for me

for you i found a vent
in the bottom of a coal mine
just enough space for your hands in the inside

if you go
do let me know

a den or a dessert
perhaps an ink squirt
a cellar, a wishing well, a war
or a guarantee will do for me

for you i found a cell
on the top floor of a prison
just enough space for you to fit your feet in

if you go
please let me know

2014年6月22日 星期日

New Toy - PX4FLOW

I just received the notice that my toy arrived! It is PX4FLOW, you can find more information here: https://pixhawk.org/modules/px4flow

It is highly sensor-integrated device. The device fused optical flow CMOS camera, sonar sensor and gyro.

Besides, its CPU is STM32F4 which I have some experience about this Cortex M4 core. I want to implement some algorithm on it achieving visual odometry.

Test it on qGrouncontrol-pixhawk


ps. PX4FLOW can be bought here: http://goods.ruten.com.tw/item/show?21405213979317

2014年6月20日 星期五

PID Performance Indices

When writing the PID Lab program, I need some indices for evaluate the controller.
There are three useful values:                                                    
  • Rise Time: time duration from 10% to 90% of final value
  • Settling Time: time to approach the final value (within the error band)
  • Time Constant: when output value approaches 63.2% of desired value



It seems Settling time is a good index using in this case because it's not only can estimate the performance but be a stop condition.

But I encounter a strange phenomenon that sometimes it soon to complete controlling and sometimes not. (about 4-1) And the first run is the longest and is prone to find steady state error.

BBB Serial Debug

Just a quick Note
  • J1 = GND (Ground)
  • J2 = CTS
  • J3 = VCC (5V)
  • J4 = RXD (Receive Data)
  • J5 = TXD (Transmit Data)
  • J6 = RTS
And its pin map

2014年6月19日 星期四

Compiling uROSnode

uROSnode
We can find it on Github: https://github.com/openrobots-dev/uROSnode
It is a great work for MCU can run ROS.
https://dl.dropboxusercontent.com/u/2771793/uros/doc/html/pag_demos.html
One great explainition about this project: pdf
ROSCon: http://vimeo.com/66970254

Problem 1:
Compiling ./src/urosUser.c
In file included from ../../include/urosUser.h:45:0,
                 from ./src/urosUser.c:42:
./src/urosUser.c: In function 'urosUserParamUpdate':
./src/urosUser.c:353:21: error: 'UrosRpcParam' has no member named 'class'
     urosError(paramp->class != UROS_RPCP_INT, return UROS_ERR_BADPARAM,
                     ^
../../include/urosBase.h:323:50: note: in definition of macro 'urosError'
 #  define urosError(when, action, msgargs) { if (when) { action; } }
                                                  ^
./src/urosUser.c:368:21: error: 'UrosRpcParam' has no member named 'class'
     urosError(paramp->class != UROS_RPCP_INT, return UROS_ERR_BADPARAM,
                     ^
../../include/urosBase.h:323:50: note: in definition of macro 'urosError'
 #  define urosError(when, action, msgargs) { if (when) { action; } }
                                                  ^
./src/urosUser.c:383:21: error: 'UrosRpcParam' has no member named 'class'
     urosError(paramp->class != UROS_RPCP_INT, return UROS_ERR_BADPARAM,
                     ^
../../include/urosBase.h:323:50: note: in definition of macro 'urosError'
 #  define urosError(when, action, msgargs) { if (when) { action; } }
                                                  ^
make: *** [build/obj/urosUser.o] Error 1
Fix:
Find the struct in uROSnode/include/urosRpcCall.h

typedef struct UrosRpcParam {

  uros_rpcparamclass_t      pclass;      /**< @brief Parameter pclass.*/

  union {

    UrosString              string;     /**< @brief XMLRPC string.*/

    int32_t                 int32;      /**< @brief XMLRPC int/i4.*/

    uros_bool_t             boolean;    /**< @brief XMLRPC boolean.*/

    double                  real;       /**< @brief XMLRPC double.*/

    UrosString              base64;     /**< @brief XMLRPC base64.*/

    void                    *mapp;      /**< @brief XMLRPC struct (map pointer).*/ /* TODO */

    struct UrosRpcParamList *listp;     /**< @brief XMLRPC array (list pointer).*/

  }                         value;      /**< @brief Parameter value.*/

} UrosRpcParam;


Then, just change the variable name from class to pclass. The error seems caused by typo.


Problem 2:
/src/lld/lwip/uros_lld_conn.c:784: undefined reference to `netconn_set_sendtimeout'

At first, I think it seems the lwip version caused error.
Change from 1.4.0 to 1.4.1
However, problem still exist.
/../../ext/lwip/src/api/api_lib.c:627: undefined reference to `sys_now'
build/obj/api_msg.o: In function `do_writemore':
/home/kv/rosnode/ChibiOS_2.5.1/demos/uROSnode/demos/turtlesim-chibios+lwip/../../../../ext/lwip/src/api/api_msg.c:1228: undefined reference to `sys_now'
collect2: error: ld returned 1 exit status
make: *** [build/turtlesim.elf] Error 1
Fix:
Then i just do the dirty thing. That I comment sys_now in 
lwip/src/api/api_msg.c
and 
lwip/src/api/api_lib.c
cause they have no instance.

Finally, the compilation is d
one.

st-flash write build/turtlesim.bin 0x08000000
2014-06-19T16:29:51 INFO src/stlink-common.c: Starting verification of write complete
2014-06-19T16:29:54 INFO src/stlink-common.c: Flash written and verified! jolly good!

But it doesn't Run! Obviously, we have different hardware module with their. 



The difficulty then will be porting the peripheral to the STM32F407 which we using Discovery.

I think porting this could be a great help to my robot!

2014年6月18日 星期三

DC Motor Speed PID Control with Arduino

It is a new MechLab for NCKU ME next semester, a PID controller!
Hardware:





Source Code on Github: https://github.com/kvzhao/ME-PIDLab

The crucial part of the PID code is listed below
void loop()
{
    // Run a period to estimate more precise speed
    Motor.Tick();
    // Run for one Second
    delay(SamplingTime);
    Motor.Tock();

    // Read rotation speed from Encoder
    Input = Motor.getSpeedRPS();

    // PID Compute
    PID_Controller.Compute();
    if ((Output-prevOutput) >= oscGap) {
      //Output = prevOutput;
    }
    Motor.setSpeed(Output);
    prevOutput = Output;
    // Show Data
    /*
    Serial.print("Input: ");
    Serial.println(Input);
    Serial.print("Setpoint: "); 
    Serial.println(Setpoint);    
    Serial.print("Error: ");
    Serial.println(error);
    Serial.print("Output: "); 
    Serial.println(Output);*/
    Serial.println(error);
    // wait a little while
    delay(5);
}


My first test result (with KP=98, KI=8, PD=5)
There is almost no steady state error, however overshoot happens.
Next step is to tune the parameters and control the motor smoothly!

Some useful references