Codes: MODERN ROBOTICS Ch.3_Expo. Coods.基础代码实现
%%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.基础代码实现的更多相关文章
- Codes: MODERN ROBOTICS Ch.4_基于PoE的正运动学代码实现
%%1 基于PoE space form 的正运动学求解 % 输入M矩阵.螺旋轴列表Slist(column vector).关节角向量qlist(column vector),输出齐次变换矩阵T f ...
- <<Modern CMake>> 翻译 2. CMake 基础
<<Modern CMake>> 翻译 2. CMake 基础 最低版本 这是每个 CMakeLists.txt 文件的第一行.CMakeLists.txt 是 CMake 所 ...
- [译]Vulkan教程(04)基础代码
[译]Vulkan教程(04)基础代码 General structure 通用结构 In the previous chapter you've created a Vulkan project w ...
- Mysql基础代码(不断完善中)
Mysql基础代码,不断完善中~ /* 启动MySQL */ net start mysql /* 连接与断开服务器 */ mysql -h 地址 -P 端口 -u 用户名 -p 密码 /* 跳过权限 ...
- 如何保障Go语言基础代码质量?
为什么要谈这个topic? 实践中,质量保障体系的建设,主要针对两个目标: 一是不断提高目标业务测试覆盖率,保障面向客户的产品质量:二就是尽可能的提高人效,增强迭代效率.而构建全链路质量卡点就是整个体 ...
- C++基础代码--20余种数据结构和算法的实现
C++基础代码--20余种数据结构和算法的实现 过年了,闲来无事,翻阅起以前写的代码,无意间找到了大学时写的一套C++工具集,主要是关于数据结构和算法.以及语言层面的工具类.过去好几年了,现在几乎已经 ...
- <<Modern CMake>> 翻译 2.3 与代码通信
<<Modern CMake>> 翻译 2.3 与代码通信 配置文件 CMake 允许您使用代码通过 configure_file 存取 CMake 变量. 此命令复制一个文件 ...
- 001-脚手架发展,基础代码结构+mybatis代码生成
一.概述 脚手架是为了保证各施工过程顺利进行而搭设的工作平台. 编程领域中的“脚手架(Scaffolding)”指的是能够快速搭建项目“骨架”的一类工具. java变成中,架构师搭建的代码结构你到处拷 ...
- java:Spring框架1(基本配置,简单基础代码模拟实现,spring注入(DI))
1.基本配置: 步骤一:新建项目并添加spring依赖的jar文件和commons-logging.xx.jar: 步骤二:编写实体类,DAO及其实现类,Service及其实现类; 步骤三:在src下 ...
随机推荐
- LIST<>泛型集合取得对象的属性值
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- [LeetCode] 93. Restore IP Addresses 复原IP地址
Given a string containing only digits, restore it by returning all possible valid IP address combina ...
- Java内存分析工具
内存分析工具 IDEA插件(VisualVM Launcher) 执行main函数的时候,同时启动jvisualvm,实时查看资源消耗情况.如图效果: Eclipse Memory Analyzer ...
- 北京WINUI外包团队:长期开发各类基于WINUI框架应用项目
今年早些时候的Build 2018中,微软高层表示,使用.NET Core 3.0,开发人员将获得使用WPF.Windows Forms和XAML Islands(WinForms和WPF应用程序中的 ...
- VMware的包格式vmdk转换为virtualBox的ova
使用winxp的vmdk作为案例 1 使用vmvare导入vmdk的winxp,点击文件---->导出为ovf 2 找到生成的ovf文件 3 打开virtualBox 管理---->导入虚 ...
- Python 获取文件类型后缀
import os path='file.txt' file=os.path.splitext(path) filename,type=file print(filename) print(type)
- [转帖]为什么需要 Zookeeper
为什么需要 Zookeeper 柳树 学习&思考&写作 | 公众号:柳树的絮叨叨 关注他 童话 . 沈万马 等 351 人赞同了该文章 很多中间件,比如Kafka.Hadoop.HB ...
- Apache Kafka Connect - 2019完整指南
今天,我们将讨论Apache Kafka Connect.此Kafka Connect文章包含有关Kafka Connector类型的信息,Kafka Connect的功能和限制.此外,我们将了解Ka ...
- PAT(B) 1075 链表元素分类(Java)
题目链接:1075 链表元素分类 (25 point(s)) 题目描述 给定一个单链表,请编写程序将链表元素进行分类排列,使得所有负值元素都排在非负值元素的前面,而 [0, K] 区间内的元素都排在大 ...
- springboot项目 配置https
感谢 https://www.jianshu.com/p/1b7b9e0803c6 帮我解决了问题 生成自签名证书 keytool -genkey -storetype PKCS12 -keysiz ...