%%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. ThinkPHP5.1的数据库链接和增删改查

    一.数据库的链接方式 <?phpnamespace app\index\controller;use think\Db; class Demo{//1.全局配置 config/database. ...

  2. SpringBoot中的@ConfigurationProperties

    有什么用 该注解的作用类似于@Value,即为组件中的属性进行赋值. 怎么用 首先是建立一个springboot的工程,不再赘述. 首先我们建立一个Person类和一个Dog类. package co ...

  3. LeetCode 75. 颜色分类(Sort Colors) 30

    75. 颜色分类 75. Sort Colors 题目描述 给定一个包含红色.白色和蓝色,一共 n 个元素的数组,原地对它们进行排序,使得相同颜色的元素相邻,并按照红色.白色.蓝色顺序排列. 此题中, ...

  4. [Oracle] - 查看数据库中每个表占用空间大小,及进行表压缩

    查询用户创建的表 select * from user_tab_comments; -- 查询本用户的表,视图等. select * from user_col_comments; -- 查询本用户的 ...

  5. 1.jvm思维导图

    点击图片可查看高清图

  6. Delphi Sysem.JSON 链式写法

    链式写法有很多优点:连贯.语意集中.简洁.一气呵成.可读性强.比如要把 3.1415926 中的 59 提取为一个整数:Pi.ToString().Substring(5,2).ToInteger() ...

  7. 2019-10-11 ubuntu ssh远程免密登录配置及配置别名

    在客户端能正常远程访问服务端的前提下. 客户端: 1)配置免密 执行 ssh-keygen 即可生成 SSH 钥匙,回车三次. 执行 ssh-copy-id user@remote,可以让远程服务器记 ...

  8. golang隐藏/显示window系统下的黑色命令窗(hide/show console)

    导入包import "github.com/gonutz/ide/w32" //隐藏consolefunc HideConsole(){ ShowConsoleAsync(w32. ...

  9. mysql_select 单表查询

    select *         *代表全部   查询多个字段 select  字段1,字段2,字段3   聚合函数  count(*)       统计 select count(*)       ...

  10. BZOJ4141 THUSC2013 魔塔 贪心

    没得传送门 考虑当\(Atk\)增大时,\(Def\)一定越来越没用,因为回合数在变少.所以考虑从小到大枚举\(Atk\)然后双指针计算. 设\(f_i(x)\)表示在\(Atk = i\)时,\(D ...