%%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. 【linux基础】Ubuntu16.04桌面突然卡住怎么办?

    使用Ctrl+Alt+F1先进入命令行模式,然后根据问题进行相应的操作. re 1. Ubuntu16.04桌面突然卡住怎么办; 2. Ubuntu下图形界面卡死解决办法; end

  2. [LeetCode] 12. Integer to Roman 整数转为罗马数字

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...

  3. [LeetCode] 242. Valid Anagram 验证变位词

    Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Input: ...

  4. nginx启动命令以及与配置systemctl

    一.配置systemctl之前的启动方式 进入sbin目录下执行以下命令: 启动nginx的命令为 /usr/local/nginx/sbin/nginx 3 停止nginx的命令为 /usr/loc ...

  5. RAID磁盘阵列结构

    RAID磁盘阵列结构原理其实很简单,就是每块硬盘不插在主板的硬盘接口上了,而是全插在RAID卡上,然后RAID卡再插到主板上,由RAID卡统一管理硬盘,做各种RAID磁盘策略(RAID0,RAID1, ...

  6. Appium元素定位难点:tap坐标定位不准确

    tap用法 1.tap是模拟手指点击页面上元素语法有两个参数,第一个是positions,是list类型最多五个点,duration是持续时间,单位毫秒 tap(self, positions, du ...

  7. 谷歌浏览器调试javascript方法

    谷歌浏览器调试javascript方法 1 ctrl + shift + f 全局文件搜索 然后加断点 也可以直接编辑js文件 保存后 就更新了 一般用在点击事件上 ps:如果加了断点 刷新浏览断点消 ...

  8. 可扩展标记语言XML之一:XML的概念、作用与示例

    哈喽大家好啊,乐字节小乐又来给大家分享Java技术文章了.上次已经讲完了Java多线程相关知识(可以看我博客文章), 这次文章将讲述可扩展标记语言XML 一. 标记语言 标记语言,是一种将文本(Tex ...

  9. JavaScript原生封装ajax请求和Jquery中的ajax请求

    前言:ajax的神奇之处在于JavaScript 可在不重载页面的情况与 Web 服务器交换数据,即在不需要刷新页面的情况下,就可以产生局部刷新的效果.Ajax 在浏览器与 Web 服务器之间使用异步 ...

  10. 通过元类创建一个Python类

    通过元类创建一个Python类 最开始学pytohn的时候我们这样定义类 class ClassName: pass 当熟悉了元类的概念之后我们还可以这样创建 ClassName = type(&qu ...