%%1 Transform omega to so3 matrix
% W for skew-symmetirc matirx
% w for omega, angular velocity
function [so3mat]=vecToso3r(omg)
so3mat=[[0, -omg(3), omg(2)];
[omg(3), 0, -omg(1)];
[-omg(2), omg(1), 0]];
end
%------------EOF------------- %%2 输入6-vector,输出se3
function S_mat = VecTose3r(S)
w = S(1:3);
v = S(4:6);
w_mat = vecToso3r(w);
S_mat = [w_mat, v; 0, 0, 0, 0];
end
%------------EOF------------- %%3 so3 to Angular velocity
function [omg]=so3ToVecr(so3mat)
omg(1)=so3mat(3,2);
omg(2)=so3mat(1,3);
omg(3)=so3mat(2,1);
end
%------------EOF------------- %%4 根据se3矩阵求6-vector
function s=se3ToVecr(S)
W = S(1:3, 1:3);
v = S(1:3, 4);
w = so3ToVecr(W);
s = [w'; v];
end
%------------EOF------------- %%5 从wtheta中分离出w与theta (开始忘了讨论了!)
function [w, theta] = AxisAng3r(wtheta)
% |w|=1必然成立,故若wtheta=0,则theta=0,w无法求解
if NearZero(norm(wtheta))
theta = 0;
w = 'cannot find';
% theta!=0,可以作为分母除
else
theta = norm(wtheta);
w = wtheta./theta;
end
%------------EOF------------- %%6 从Stheta中分离出S与theta(也是忘了讨论!)
function [S, theta] = AxisAng6r(Stheta)
wtheta = Stheta(1:3);
vtheta = Stheta(4:6);
% 如果|wtheta|=0,可能由于w=0或theta=0,需继续判断
if NearZero(norm(wtheta))
% 假设theta!=0,那么w=0,则|v|=1,则|vtheta|将求出theta值
theta = norm(vtheta);
% 如果求出的theta值为0,表明wtheta=0是由theta=0引起的,这时螺旋轴S无法找到
if NearZero(theta)
theta = 0;
S = 'cannot find';
% 如果theta值不为0,表明w=0,这时theta!=0即可作为分母除
else
w = zeros(3,1);% 这句没有作用,只是表明这种情况下是w=0
S = Stheta./theta;
end
% 如果|wtheta|!=0,则说明|w|=1且theta!=0,直接作分母除theta即可
else
theta = norm(wtheta);
S = Stheta./theta;
end
%------------EOF------------- %%7 Matrix exponential for so3
% 根据wtheta_mat,求取旋转矩阵
function [R]=MatExp3r(wtheta_mat)
% 求出w与theta
wtheta = so3ToVecr(wtheta_mat);
theta = norm(wtheta);
w = wtheta./theta;
% 求w的矩阵表示w_mat
w_mat = vecToso3r(w);
% 求矩阵指数映射
R= eye(3)+sin(theta).* w_mat+(1-cos(theta)).* w_mat^2;
end
%------------EOF------------- %%8 根据指数坐标的矩阵表示Stheta_mat,求变换矩阵T(忘了分类w=0的情况!)
function T = MatExp6r(Stheta_mat)
Stheta = se3ToVecr(Stheta_mat);
wtheta = Stheta(1:3);
vtheta = Stheta(4:6);
if NearZero(norm(wtheta))
T=[eye(3), vtheta;
zeros(1,3), 1];
else
% 计算角速度指数坐标wtheta_mat的指数映射
wtheta_mat = vecToso3r(wtheta);
R = MatExp3r(wtheta_mat);
% 分离螺旋轴指数坐标Stheta,求v向量,并求w向量的矩阵表示w_mat,并用于计算Gv
[S,theta] = AxisAng6r(Stheta);
w = S(1:3);
v = S(4:6);
w_mat = vecToso3r(w);
Gv = (eye(3).*theta+(1-cos(theta)).*w_mat+(theta-sin(theta)).*w_mat^2)*v;
% 将R、Gv、eye(1,3)、1拼接成变换矩阵T
T=[R, Gv;
eye(1,3), 1];
end
end
%------------EOF------------- %%9 矩阵对数算法,根据旋转矩阵R,求旋转指数坐标的矩阵表示wtheta_mat
% R to so3mat, namely, so3omghat.*theta
function wtheta_mat = MatLog3r(R)
if isequal(R,eye(3))
theta = 0;
fprintf('omghat is undefined');
wtheta_mat = zeros(3);
elseif trace(R)==-1
theta = pi;
if ~NearZero(1+R(3,3))
w =(1/sqrt(2*(1+R(3,3))))...
.*[R(1,3);R(2,3);1+R(3,3)]
elseif ~NearZero(1+R(2,2))
w =(1/sqrt(2*(1+R(2,2))))...
.*[R(1,2);1+R(2,2);R(3,2)]
elseif ~NearZero(1+R(3,3))
w =(1/sqrt(2*(1+R(1,1))))...
.*[1+R(1,1);R(2,1);R(3,1)]
end
w_mat = vecToso3r(w);
wtheta_mat = w_mat.*theta;
else
theta = acos((trace(R)-1)/2);
w_mat = (1/(2*sin(theta))).*(R-R');
wtheta_mat = w_mat.*theta;
end
end
%------------EOF------------- %%10 根据变换矩阵T,求螺旋指数坐标stheta_mat
function stheta_mat = MatLog6r(T)
[R,p] = TransToRpr(T);
if isequal(eye(3), R)
w = zeros(3,1);
theta = norm(p);
v = p./theta;
else
wtheta_mat = MatLog3r(R);
wtheta = so3ToVecr(wtheta_mat);
theta = norm(wtheta);
w = (wtheta)'./theta;
w_mat = vecToso3r(w);
v = ((1/theta).*eye(3)-1/2.*w_mat+(1/theta-1/2*cot(theta/2)).*w_mat^2)*p;
end
s = [w; v];
stheta = s.*theta;
stheta_mat = VecTose3r(stheta);
end
%------------EOF------------- %%11 qsh螺旋轴变换为单位螺旋轴
function S = ScrewToAxisr(q,s,h)
% Takes q: a point lying on the screw axis, column vector
% s: a unit vector in the direction of the screw axis, column vector
% h: the pitch of the screw axis.
S = [s; cross(s,-q)+h.*s];
end
%------------EOF------------- %%12 计算变换矩阵T的伴随映射
function AdT=Adjointr(T)
[R,p] = TransToRpr(T);
P = vecToso3r(p);
AdT=[R, eye(3);
P*R, R];
end
%------------EOF-------------

  All codes are written in function format, and pay attention to codes #5、6、8、9、11  !

Codes: MODERN ROBOTICS Ch.3_Expo. Coods.基础代码实现的更多相关文章

  1. Codes: MODERN ROBOTICS Ch.4_基于PoE的正运动学代码实现

    %%1 基于PoE space form 的正运动学求解 % 输入M矩阵.螺旋轴列表Slist(column vector).关节角向量qlist(column vector),输出齐次变换矩阵T f ...

  2. <<Modern CMake>> 翻译 2. CMake 基础

    <<Modern CMake>> 翻译 2. CMake 基础 最低版本 这是每个 CMakeLists.txt 文件的第一行.CMakeLists.txt 是 CMake 所 ...

  3. [译]Vulkan教程(04)基础代码

    [译]Vulkan教程(04)基础代码 General structure 通用结构 In the previous chapter you've created a Vulkan project w ...

  4. Mysql基础代码(不断完善中)

    Mysql基础代码,不断完善中~ /* 启动MySQL */ net start mysql /* 连接与断开服务器 */ mysql -h 地址 -P 端口 -u 用户名 -p 密码 /* 跳过权限 ...

  5. 如何保障Go语言基础代码质量?

    为什么要谈这个topic? 实践中,质量保障体系的建设,主要针对两个目标: 一是不断提高目标业务测试覆盖率,保障面向客户的产品质量:二就是尽可能的提高人效,增强迭代效率.而构建全链路质量卡点就是整个体 ...

  6. C++基础代码--20余种数据结构和算法的实现

    C++基础代码--20余种数据结构和算法的实现 过年了,闲来无事,翻阅起以前写的代码,无意间找到了大学时写的一套C++工具集,主要是关于数据结构和算法.以及语言层面的工具类.过去好几年了,现在几乎已经 ...

  7. <<Modern CMake>> 翻译 2.3 与代码通信

    <<Modern CMake>> 翻译 2.3 与代码通信 配置文件 CMake 允许您使用代码通过 configure_file 存取 CMake 变量. 此命令复制一个文件 ...

  8. 001-脚手架发展,基础代码结构+mybatis代码生成

    一.概述 脚手架是为了保证各施工过程顺利进行而搭设的工作平台. 编程领域中的“脚手架(Scaffolding)”指的是能够快速搭建项目“骨架”的一类工具. java变成中,架构师搭建的代码结构你到处拷 ...

  9. java:Spring框架1(基本配置,简单基础代码模拟实现,spring注入(DI))

    1.基本配置: 步骤一:新建项目并添加spring依赖的jar文件和commons-logging.xx.jar: 步骤二:编写实体类,DAO及其实现类,Service及其实现类; 步骤三:在src下 ...

随机推荐

  1. [LeetCode] 309. Best Time to Buy and Sell Stock with Cooldown 买卖股票的最佳时间有冷却期

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  2. E: Unable to correct problems, you have held broken packages-之apt-get 下载报依赖问题

    今天在新来了一台ubutnu 18.04 在安装zabbix客户端是报依赖问题 root@VM_0_10:~# apt-get install zabbix-agent Reading package ...

  3. android基础---->Toast的使用

    简要说明 Toast是一种没有交点,显示时间有限,不能与用户进行交互,用于显示提示信息的显示机制,我们可以把它叫做提示框.Toast不依赖 于Activity,也就是说,没有Activity,依然可以 ...

  4. 学习记录-java基础部分(一)

    学习记录-java基础部分(一) 参考:GitHub上的知名项目:javaGuide : https://github.com/Snailclimb/JavaGuide/blob/master/doc ...

  5. IO多路复用(select、poll、epoll)介绍及select、epoll的实现

    IO多路复用(select.poll.epoll)介绍及select.epoll的实现 IO多路复用中包括 select.pool.epoll,这些都属于同步,还不属于异步 一.IO多路复用介绍 1. ...

  6. SpringMVC中静态资源的处理

    web项目中web.xml配置 在一个使用springmvc的web项目中,必然在web.xml中要配置前端控制器DispatcherServlet <servlet> <servl ...

  7. 下一代无服务器的发展形态: Serverless2.0

    6 月 25 日,在上海召开的 KubeCon 2019 大会上,腾讯云重磅发布了下一代无服务器的发展形态:Serverless2.0.本文将以 Serverless 的概念.发展.形态.应用以及技术 ...

  8. 备份数据库中的某个表的数据报错Statement violates GTID consistency

    1.错误描述 执行CREATE TABLE tig_pairs_20190521 AS SELECT *FROM tig_pairs报错: 1 queries executed, 0 success, ...

  9. Django 修改该项目文件夹、项目名及项目文件夹中同名文件夹,报错 ModuleNotFoundError: No module named 'untitled'

    如果你直接重构项目文件夹名及重构项目名和重构项目文件夹内同名文件夹 执行项目报错 ModuleNotFoundError: No module named 'untitled' 请执行以下操作

  10. 记28377系列芯片中Can总线标准帧和扩展帧该怎么设置?

    笔者最近在调试28377系列DSP芯片的can通讯时,遇到一个小问题,百思不得姐~ 起因是这样的,在设计一个多单元并联的系统,所有单元使用can总线进行通讯,当通讯端口,can外设,以及相关通讯协议都 ...