Hanjie's Blog

一只有理想的羊驼

Ros Indigo版本默认使用的是2.4.8版本的OpenCV,实在是太旧了。于是我clone了最新的3.3版本,build了之后,参考了1上的解决方案,修改了package的cmakelists.txt文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# don't use opencv as found by any prior running of find_package
unset(OpenCV_CONFIG_PATH CACHE)
unset(OpenCV_DIR CACHE)

set(TMP_PREFIX_PATH ${CMAKE_PREFIX_PATH})
set(CMAKE_PREFIX_PATH "$ENV{HOME}/special/install")
set(OpenCV_DIR "./opencv-3.3.0/build")
find_package(OpenCV 3.3 EXACT REQUIRED)

message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")

# restore CMAKE_PREFIX_PATH and other cached variables
# so nothing other package finds this opencv
set(CMAKE_PREFIX_PATH ${TMP_PREFIX_PATH})

unset(OpenCV_CONFIG_PATH CACHE)
unset(OpenCV_DIR CACHE)

...

include_directories(
include
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)

target_link_libraries(foo_node
${OpenCV_LIBS}
${catkin_LIBRARIES}
)

注意在target_link_libraries中,${OpenCV_LIBS}需要放到${catkin_LIBRARIES}之前,不然系统有可能会先调用系统默认的2.4.8版本的OpenCV。

如果cv_bridge发生冲突,可以从这里,下载cv_bridge,并且使用高版本的OpenCV编译cv_bridge


  1. https://answers.ros.org/question/214043/use-ros-indigo-opencv3-alongside-248/↩︎

Hanjie Luo
School of Electronic and Computer Science
University of Southampton
6 February, 2011

Introduction

The basic rules of evolutionary games

Evolution of cooperative behaviour is widely existent in the biological organisms and social systems. In order to research the evolution of cooperation, some classical evolutionary games have been used, and Prisoners’ Dilemma (PD) is one of the famous models.

In this paper, I use a simplified version of Prisoners Dilemma which is played by two kinds of plays: those who always apply cooperation strategy, C, and those who always apply defection strategy, D, on a two-dimensional, n×n lattice with fixed boundary conditions. Each position is only occupied by a C or a D. The payoff matrix which describes the interaction is as follows:

1
2
3
    C   D
C 1 0
D b 0

where, b is the only parameter which represents the advantage for defectors. In each generation of the game, each site-owner receives a score which is the sum of the pay-offs with 8 immediate neighbours and itself. In the next generation, each lattice-site is replaced by the highest-scoring player among 8 immediate neighbours and itself. I also explored the game played with only 8 immediate neighbours without self-interaction and 4 orthogonal neighbours with self-interaction.

Consequently, different chaotically changing patterns can be generated by setting different initial condition and different regimes of parameter b. Nowak and May observed that \(2>b>1.8\) is the most significant regime where C and D both will grow which makes the frequency of cooperators always reaches approximately 0.318 regardless of initial conditions (1992: 826).

As an extension, I study the evolutionary game in three-dimensional space and predict that it has the same performance as the game in two-dimensional space.

Reimplemented Results

8-neighbours with self-interaction

Figure 1 shows two different asymptotic patterns which are generated by PD for two different magnitude ob b. for \(1.75<b<1.8\), D clusters will shrink while C will continue to grow. In this situation, figure 1a and 1b show that some D line fragments exist on the background of C. Figure 1c and 1d are for the significant regime \(1.8<b<2\) where C and D both persist in expending thereby creating the chaotic dynamic patterns. However, figure 2 shows that the frequency of cooperators \({f_c}\) is completely independent of all the starting conditions, which is around \(12\log 2 - 8 = 0.318\) (Nowak and May 1992: 826). It seems that there is a universal constant hiding in the PD.

Simulations of evolutionary games in space 1

Figure 1. These figures are the patterns which are generated by Prisoners’ Dilemma for different magnitude of b. (a) and (c) are the original pictures from paper while (b) and (d) are reimplemented figures. All simulations start with the initial condition with 10% defectors at a 200×200 square-lattice with fixed boundary conditions. The figures show the generation \(t>100\). The colour coding is as follows: blue, a C site which was a C in the previous generation; red, a D site which was D; yellow, a D following a C; green, a C following a D. (a) and (b) are the patterns when \(1.75<b<1.8\) whereas (c) and (d) are the patterns when \(1.8<b<2\). (Nowak and May 1992: 827)

Simulations of evolutionary games in space 2

Figure 2. The frequency of cooperators with random initial conditions. (a) is the original figure from paper while (b) is reimplemented figure. The dashed or red line represents \({f_c=0.318}\). Conditions: 400×400 square lattice with fixed boundaries conditions, 8 neighbours plus self-interaction, \({f_c(0)=0.6}\), \(1.8<b<2\), 300 generations. (Nowak and May 1992: 827)

8-neighbours without self-interaction

A similar result was obtained by excluding self-interaction. However, there is a small different on the regimes of b values. The C clusters will continue to grow when \(b<5/3\) while D clusters will keep growing when \(b>8/5\). As a result, the most significant region is \(8/5<b<5/3\) where both C and D will continue to grow (Nowak and May 1992: 57). Figure 3a shows a symmetric pattern which starts from a single D at the centre of Cs. Figure 3b reveals that the frequency will converge to around 0.300 for random starting conditions, which is slight different from figure 2.

Simulations of evolutionary games in space 3

Figure 3. (a) The symmetric pattern generated by the evolutionary games. It begins with a single D at the centre of a 99×99 square lattice of Cs with fixed boundary conditions. Other conditions: 8-neighbours without self-interaction, \(8/5<b<5/3\), generations=218. (b) The frequency of cooperators for a 400×400 square lattice with fixed boundaries conditions, random initial conditions (10% defectors), \(8/5<b<5/3\), generations=300. The red line represents 0.300.

4-neighbours with self-interaction

The game played with 4 orthogonal neighbours plus self-interaction is also explored. The interesting regime has become \(5/3<b<2\) (Nowak and May 1992: 829). Figure 4a shows a different complex pattern contrasting with figure 3a. Similarly, figure 4b manifests that the frequency will converge to around 0.376 for random starting conditions.

By observing through figure 2, figure 3b and figure 4b, the frequency of cooperators always converge to a specific proportion. So, it seems that the results of the evolutionary games have some kind of robustness.

Simulations of evolutionary games in space 4

Figure 4. (a) The symmetric pattern of a square-lattice with 4 neighbours plus self-interaction which begins with a single D at the centre of a 99×99 square lattice of Cs with fixed boundary conditions, \(5/3<b<2\), generations=218. (b) The frequency of cooperators for a 400×400 square lattice with fixed boundaries conditions, random initial conditions (10% defectors), \(5/3<b<2\), generations=300. The red line represents 0.376.

Extensions

Evolutionary games in three dimensions

Introduction

The evolutionary games above are all played in two dimensions. So, it is interesting to study the evolutionary games in three dimensions and see what difference it makes contrasting to the games in two dimensions.

The basic rules are almost the same as two-dimensionl versions except the players are placed on an n×n×n cubic world. The interaction of the games is with the 26 immediate neighbours plus self-interaction.

The purpose of PD is to simulate the cooperate behaviors among biological organisms and social systems in the real world. However, the world we lived in is three-dimensional. Consequently, it is necessary to simulate in three dimensions for reaching valid results about real world. It is reasonable to forecast that the results of the games in three dimensions are very similar to the games in two dimensions which can also generate the symmetric patterns and the frequency will converge to a specified value because these results are widely seen in the games in two dimensions.

Results of extension

By experiment, I find that if \(b>1.421\), a 2×2×2 cube of D will keep growing at the corners while a 2×2×2 cube of C will keep expanding if \(b<2\). So the interesting regime has become \(1.421<b<2\) where both C and D will keep growing. Figure 5 shows different patterns for two different regimes of b values which both started with a single D at the centre Cs. For \(1.421<b<1.5\), I find symmetric patterns emerged while the patterns have become chaotic if \(1.5<b<2\), which is slight different from games played in two dimensions. Figure 6 shows that the frequency will converge to around 0.535 for all random starting conditions.

Simulations of evolutionary games in space 5

Figure 5. The patterns generated by PD in three dimensions. The games are played in a 45×45×45 cube with fixed boundary conditions. The interaction of the games is with the 26 immediate neighbours plus self-interaction. Both figures show a middle slice, 150 generations after having started with a single D at the centre Cs. (a) \(1.421<b<1.5\) (b) \(1.5<b<2\).

Simulations of evolutionary games in space 6

Figure 6. The frequency of cooperators for a 45×45×45 cube with fixed boundaries conditions, random initial conditions (10% defectors), \(1.421<b<2\), generations=200. The interaction of the games is with the 26 immediate neighbours plus self-interaction. The red line represents 0.535.

Conclusion

The results of simulations reveal that the PD in three dimensions has the same characteristics as the PD in two dimensions. As a result, we can use PD in two dimensions, which is less computing contrasting with PD in three dimensions, for simulating this three-dimensional real world.

Evolutionary games with asynchronous updating

Introduction

The rule described above means that all players are updated their states at the same time. However, a global clock which synchronizes their interactions is non-existent in a natural system. Consequently, it is necessary to update the states continuously and asynchronously for simulating a real world system (Huberman and Glance 1993: 7717).

In order to realize asynchronous updating, a small enough interval of time, which makes at most one site-owner interactions within that time interval, is randomly chosen. The chosen site-owner interactions with its neighoubers (with or without self-interaction) and replaces its state immediately while other states of site-owners stay constant. Consequently, the environment of the world will be changed slightly and continuously at each time interval. This procedure will continue until all entities have been chosen once.

Results of extension

Figure 8 shows that a synchronously updated games starts with a single D at the centre of Cs. The array will be eventually full of Ds within 100 generations, which is quite different contrasting with the synchronous version.

However, the situations are quite different when the interaction is with 4 neighbours plus interaction. Figure 9a reveals that the frequency will converge to around 0.500 for random starting conditions (including a single D at the centre of Cs). Figures 9b shows a similar pattern comparing with figure 1a.

Simulations of evolutionary games in space 7

Figure 8. The frequency of cooperators with asynchronous updating. The games begin with a single D at the centre of a 99×99 square lattice of Cs with fixed boundary conditions. (a) Conditions: 8 neighbours plus self-interaction, \(1.8<b<2\). (b) Conditions: 8 neighbours exclude self-interaction, \(8/5<b<5/3\).

Simulations of evolutionary games in space 8

Figure 9. The results of PD with asynchronous updating. The games play at a 99×99 square lattice with fixed boundaries conditions, random initial conditions (10% defectors), \(5/3<B<2\), generations=800. (a) The frequency of cooperators. The red line represents 0.500. (b) The 800th generation of patterns.

Conclusion

The experiments show that, in an asynchronously updated game, the array will always be full of Ds as long as a C in the initial conditions when the interaction is with 8 neighbours with or without self-interaction. What’s more, I also find the frequency of cooperators always converge to a specific proportion if the interaction is with 4 neighbours plus self-interaction, which is the same characteristic occurring in synchronous version.

Recosures

Source Code

References

Nowak, M, A and May, R, M 1992, ‘Evolutionary games and spatial chaos’, Nature, vol. 359, pp. 826-829.

Nowak, M, A and May, R, M 1993, ‘THE SPATIAL DILEMMAS OF EVOLUTION’, International Journal of Bifurcation and Chaos, vol. 3, no.1, pp. 35-78.

Huberman, B, A, and Glance, N, S, 1993, ‘Evolutionary games and computer simulations’, Proceedings of the National Academy of Sciences, vol. 90, no. 16, pp. 7716-7718.

罗汉杰. 机械臂的控制方法和装置:中国,201610984458[P/OL]. 2017-03-01 [2018-03-20]. https://patentimages.storage.googleapis.com/7c/c5/c2/165019b55f0bee/CN106346478A.pdf

Introduction

机械臂的轨迹规划程序中,程序会接受用户提供的起点,终点位置信息,然后程序会在两点之间生成一系列的插补点来描述机械臂末端应该运行的轨迹。

当用户提供多条直线线段,并且要求机械臂末端依次沿着直线运行时,程序需要在每两条线段的手尾位置规划出一个过渡段,使得机械臂终端能够平稳地从一个运动方向转到另一个运动方向。为保证机械臂运行效率和精度,需要机械臂在整个运行过程中位移,速度,加速度参数必须连续。

本文提出了一种用于机械臂的轨迹规划算法,能够使得机械臂从当前状态开始规划出一条位移,速度,加速度连续的过渡轨迹,到要运行的直线轨迹上。

Approach

给定机械臂目标直线的起点\(P_1\),终点 \(P_2\)。其中\(P\)表示笛卡尔坐标系下的位置参数\(P_i=[x_i,y_i,z_i ]^T\)。给定当前的机械臂关节空间角度\(Q_0=[q_0,q_1,…,q_n ]^T\),其中\(n\)为机械臂的关节数目,同理给定机械臂关节角速度\({\dot Q_0}\),关节角加速度\({\ddot Q_0}\)

使用S 型(Double S)速度规划/多阶样条插值/b样条插补等方法,规划出直线线段\(P_1 P_2\)在笛卡尔坐标系下的插补点\(P_t=[x_t,y_t,z_t ]^T\),速度\(\dot P_t=[\dot x_t,\dot y_t,\dot z_t ]^T\),加速度\(\ddot P_t=[\ddot x_t,\ddot y_t,\ddot z_t ]^T\)\(t\)为时间点,总运行时间为\(t_{line\_all}\)

给定参数时刻\(t_s (0≤t_s≤t_{line\_all})\)(可根据给定的一个比例参数\(r_s\) 获得参数\(t_s=t_{line\_all}*r_s)\),并从已规划出的直线\(P_1 P_2\)上,获得时刻\(t_s\)时的坐标点\(P_s\),速度\(\dot P_s\),加速度\(\ddot P_s\),将此点作为过渡段的终点。

使用逆运动学方法,将笛卡尔坐标系下的\(P_s\)转换到此时刻关节空间下的参数\(Q_s\)。使用以下公式将\(\dot P_s\)\(\ddot P_s\)转换为\(\dot Q_s\)\(\ddot Q_s\)

\[\begin{align} \label{e1} \dot Q &= J^+ \dot P \newline \label{e2} \ddot Q &= J^+ (\ddot P- \dot J \dot Q) \end{align}\]

其中,\(J\)为雅可比(Jacobian)矩阵,\(\dot J\)为雅可比矩阵的一阶导,\(J^+\)\(J\)的伪逆(Pseudoinverse)。

使用基于多阶多项式/三角函数等的曲轨迹生成方法,在以\(Q_0\)\(\dot Q_0\)\(\ddot Q_0\)为起点,\(Q_s\)\(\dot Q_s\)\(\ddot Q_s\)为终点,在轴空间规划出一条连续过度段轨迹,整个运行时长为\(t_{trans}\)。以五阶多项式曲线为例,先代入以下公式计算出系数参数:

\[\begin{align} a_0 &= Q_0 \notag \newline a_1 &= \dot Q_0 \notag \newline a_2 &= \ddot Q_0 / 2 \notag \newline a_3 &= \frac{20h-(8\dot Q_s+12\dot Q_0 ) t_{trans}-(3\ddot Q_0- \ddot Q_s ) t_{trans}^2 }{2t_{trans}^3} \newline a_4 &= \frac{-30h+(14\dot Q_s+16\dot Q_0 ) t_{trans}+(3\ddot Q_0-2\ddot Q_s ) t_{trans}^2}{2t_{trans}^4 } \notag \newline a_5 &= \frac{12h-6(\dot Q_s+\dot Q_0 ) t_{trans}+(\ddot Q_0-\ddot Q_s ) t_{trans}^2}{2t_{trans}^5 } \notag \label{e3} \end{align}\]

然后就可以根据以下公式计算出任意时刻\(t(0≤t≤t_{trans})\)时的关节角位置\(Q_t\),角速度\(\dot Q_t\),角加速度\(\ddot Q_t\)

\[\begin{align} \label{e4} Q_t&=Q_0+a_1 t+a_2 t^2+a_3 t^3+a_4 t^4+a_5 t^5 \newline \label{e5} \dot Q_t&=a_1+2a_2 t+3a_3 t^2+4_4 t^3+5a_5 t^4 \newline \label{e6} \ddot Q_t&=2a_2+6a_3 t+12a_4 t^2+20a_5 t^3 \end{align}\]

该过渡段的重点是,当运行到过渡段的终点时,此时的\(Q_{trans}\)\(\dot Q_{trans}\)\(\ddot Q_{trans}\),与在步骤2规划的直线线段在时刻\(t_s\)时的\(Q_s\)\(\dot Q_s\)\(\ddot Q_s\)相等,从而保证了位置,速度和加速度在数值上的连续。

所以,整个路径规划出来的线段包括过渡段和直线轨迹两个部分,其中过渡段用时\(t_{trans}\),直线段用时\(t_{line}\),总用时\(t_{all}\),其中:

\[\begin{align} \label{e7} t_{line} & =t_{line\_all}-t_s \newline \label{e8} t_{all} & =t_{trans}-t_{line} \end{align}\]

Flow Diagram

manipulation flow diagra

Experiment

下图显示了SCARA型四轴机械臂末端从坐标\([0.6,0,0]^T\)直线运行到\([0.344,0.128,0]^T\),然后使用上文提出的算法,从当前位置规划出一个过渡段曲线到\([0.189,0.2,0]^T\),然后直线运行到终点\([0,0.2,0]^T\)

manipulation d1

下图显示了机械臂的前三个轴各自在各个时刻的\(Q_t\)\(\dot Q_t\)\(\ddot Q_t\)。从图可以看到,无论是轴的角度,角速度,角加速度都连续。

manipuation d2

Conclusion

在传统的机械臂中,当要连续执行多条直线轨迹的时候,需要先执行完一条轨迹,然后停止,再执行另外一条,这种运动方式效率十分低。

另外一些机械臂中,需要预先给出所有要运行的线段,然后才能在必要的地方规划出过渡段。

在本方法中,过渡段只与机械臂当前状态,起点,终点有关,不需要其余信息,方便使用;在整个运行过程中,机械臂不需要停止,规划出来的轨迹平稳,效率高。

0%