24小时热门版块排行榜    

查看: 2784  |  回复: 7
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

szb21971

银虫 (正式写手)

[求助] 双足机器人行走棍图怎么用MATLAB画出来啊?求助啊!!! 已有1人参与

双足机器人行走棍图怎么用MATLAB画出来啊?求助啊!!!
回复此楼
共享共赢
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

blackwave

铁虫 (初入文坛)

【答案】应助回帖

★ ★ ★ ★ ★ ★ ★ ★ ★ ★
szb21971: 金币+10, 有帮助 2015-01-19 09:46:24
The following is a function I wrote to generate a stick diagram of robot motion. Hope it is helpful to you all.   

function [foot2] = stick(filename,user_frame_per_second,max_step)
global robot
foot2=[];
mov_traj = load(filename);

dt = mov_traj(2,1) - mov_traj(1,1);
frame_per_second = fix(1/dt);
if user_frame_per_second == 0
    show_frame_per_second = frame_per_second;
else
    show_frame_per_second = user_frame_per_second;
end
capture_frame_per_second = 20;
color0 = [0 0 0];
color1 = [0 0 0];
color2 = [0 0 0];
color3 = [1 1 1]*0.5;
color4 = [1 1 1]*0.5;
width = 2;
scrsz = get(0,'ScreenSize');
animation = figure;
%hold on
xxlim = [-0.8 0.8]
yylim = [ 0.0 1.6]
set(animation,'name','2D walking','Position',[100 100 450 450]);
h_axes = axes('Parent',animation,'Units','Pixels','Position',[50 40 400 400],'Ylim',yylim,'Xlim',xxlim);

%tx = text('Parent',h_axes,'Visible','off');
set(h_axes,'visible','on');
ground  = line('Parent',h_axes,'Color',[0 0 0],'Visible','off','LineWidth',2);
set(ground, 'Parent',h_axes,'Xdata',xxlim,'Ydata', [0 0],'visible','on');

idx =1
ss_flag = 0;
step_count = 0;
l_ankle_pos = zeros(2,1); l_knee_pos = zeros(2,1); l_hip_pos  = zeros(2,1); head_pos   = zeros(2,1);
r_knee_pos = zeros(2,1); r_ankle_pos = zeros(2,1);

r_ankle_pos_b_save = [-1,0]';
base = [0 0]';
for i = 1:size(mov_traj,1)
  tt = mov_traj(i,1);
  l_ankle_abs = mov_traj(i,2);
  l_knee_abs  = l_ankle_abs + mov_traj(i,3);
  l_hip_abs   = l_knee_abs + mov_traj(i,4);
  r_hip_abs   = l_hip_abs + mov_traj(i,5);
  r_knee_abs  = r_hip_abs + mov_traj(i,6);
%  r_knee_abs  = r_knee_abs;
  l_ankle_pos_b =[0 0]';
  l_knee_pos_b = [ -robot.calf_length * sin(l_ankle_abs) robot.calf_length* cos(l_ankle_abs)]';
  l_hip_pos_b  = [l_knee_pos_b(1)-sin(l_knee_abs)*robot.thigh_length  l_knee_pos_b(2)+cos(l_knee_abs)*robot.thigh_length ]';
  head_pos_b   = [l_hip_pos_b(1)-sin(l_hip_abs)*robot.torso_length l_hip_pos_b(2) + cos(l_hip_abs)*robot.torso_length]';
  r_knee_pos_b = [l_hip_pos_b(1)+sin(r_hip_abs)*robot.thigh_length l_hip_pos_b(2) - cos(r_hip_abs)*robot.thigh_length]';
  r_ankle_pos_b = [r_knee_pos_b(1)+sin(r_knee_abs)*robot.calf_length r_knee_pos_b(2) - cos(r_knee_abs)*robot.calf_length]';

  if (r_ankle_pos_b_save(1) > 0 && r_ankle_pos_b(1) < 0) % switch
      step_count = step_count +1;
      if step_count >= max_step
          break
      end
      ss_flag = 1;
    tmp = color0; color0 = color4; color4=tmp;
    tmp = color1; color1 = color3; color3=tmp;
    set(l_calf,'Color',color0,'Visible','off');
    set(l_thigh,'Color',color1,'Visible','off');
    set(torso,'Color',color2,'Visible','off')
    set(r_thigh,'Color',color3,'Visible','off');
    set(r_calf,'Color',color4,'Visible','off');
    %     hip_travel = hip_travel + r_ankle_pos_b_save(1);
%     ground_height = ground_height + r_ankle_pos_b_save(2);
    base = base + r_ankle_pos_b_save;
    %ground_height  =0 ;
    %set(h_axes,'Ylim',[-0.05+ground_height 1.95+ground_height]);
    base;
    r_ankle_pos_b_save;
    r_ankle_pos_b;
    %pause   
  end  
  r_ankle_pos_b_save = r_ankle_pos_b;
%  drift = l_hip_pos(1);
%   l_ankle_pos(1) = l_ankle_pos(1) - drift;
%   l_knee_pos(1) = l_knee_pos(1) - drift;
%   l_hip_pos(1)  = l_hip_pos(1) - drift;
%   head_pos(1)   = head_pos(1) - drift;
%   r_knee_pos(1) = r_knee_pos(1) - drift;
%   r_ankle_pos(1) = r_ankle_pos(1) - drift;
  l_ankle_pos = l_ankle_pos_b + base;
  l_knee_pos = l_knee_pos_b  + base;
  l_hip_pos  = l_hip_pos_b  + base;
  head_pos   = head_pos_b  + base;
  r_knee_pos = r_knee_pos_b  + base;
  r_ankle_pos = r_ankle_pos_b  + base;
  
  foot2 = [foot2,r_ankle_pos];


  if (mod(i,fix(frame_per_second/show_frame_per_second)) == 1 )
            torso   = line('Parent',h_axes,'Color',color2,'Visible','off','LineWidth',width);
            r_thigh = line('Parent',h_axes,'Color',color3,'Visible','off','LineWidth',width);
            r_calf  = line('Parent',h_axes,'Color',color4,'Visible','off','LineWidth',width);
            l_calf  = line('Parent',h_axes,'Color',color0,'Visible','off','LineWidth',width);
            l_thigh = line('Parent',h_axes,'Color',color1,'Visible','off','LineWidth',width);
            
            if mod(step_count,2) == 1
                set(l_calf, 'Parent',h_axes,'Xdata',[l_ankle_pos(1) l_knee_pos(1)],'Ydata', [l_ankle_pos(2) l_knee_pos(2)],'visible','on');
                set(l_thigh, 'Parent',h_axes,'Xdata',[l_knee_pos(1) l_hip_pos(1)],'Ydata', [l_knee_pos(2) l_hip_pos(2)],'visible','on');
                set(torso, 'Parent',h_axes,'Xdata',[l_hip_pos(1) head_pos(1)],'Ydata', [l_hip_pos(2) head_pos(2)],'visible','on');
                set(r_thigh, 'Parent',h_axes,'Xdata',[l_hip_pos(1) r_knee_pos(1)],'Ydata', [l_hip_pos(2) r_knee_pos(2)],'visible','on');
                set(r_calf, 'Parent',h_axes,'Xdata',[r_knee_pos(1) r_ankle_pos(1)],'Ydata', [r_knee_pos(2) r_ankle_pos(2)],'visible','on');
            else
                set(torso, 'Parent',h_axes,'Xdata',[l_hip_pos(1) head_pos(1)],'Ydata', [l_hip_pos(2) head_pos(2)],'visible','on');
                set(r_thigh, 'Parent',h_axes,'Xdata',[l_hip_pos(1) r_knee_pos(1)],'Ydata', [l_hip_pos(2) r_knee_pos(2)],'visible','on');
                set(r_calf, 'Parent',h_axes,'Xdata',[r_knee_pos(1) r_ankle_pos(1)],'Ydata', [r_knee_pos(2) r_ankle_pos(2)],'visible','on');
                set(l_calf, 'Parent',h_axes,'Xdata',[l_ankle_pos(1) l_knee_pos(1)],'Ydata', [l_ankle_pos(2) l_knee_pos(2)],'visible','on');
                set(l_thigh, 'Parent',h_axes,'Xdata',[l_knee_pos(1) l_hip_pos(1)],'Ydata', [l_knee_pos(2) l_hip_pos(2)],'visible','on');
               
            end

          stime=sprintf('time:%5.2f',tt);
      %set(tx,'Parent',h_axes,'Position',[l_hip_pos(1),1.8],'String',stime,'visible','on');
      %set(h_axes,'Xlim',[l_hip_pos(1)-1.0 l_hip_pos(1)+1.0]);
      drawnow;
  end
  if l_ankle_pos(1) > xxlim(2)
      break
  end
end
xlabel('(m)')
ylabel('(m)')
7楼2015-01-15 11:38:18
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 8 个回答

szb21971

银虫 (正式写手)

我也看到这个了,可是没有看懂,您会这个东西吗?太着急了!
共享共赢
2楼2015-01-11 11:14:47
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

szb21971

银虫 (正式写手)

我也找到这个了,可是,我还是没有弄明白,比较着急哈
共享共赢
3楼2015-01-11 11:15:36
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

sichanglong

铁虫 (小有名气)

是要画出关节的连线的连续运动图么?
我郁闷呀,啥都不会,还要写报告。。。。:(
4楼2015-01-11 16:20:18
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] FileCode能看出啥? +7 要乐观耀哥 2026-08-10 16/800 2026-08-11 08:18 by wmfsnow
[基金申请] 为什么网上很多人说本周 12号出结果 +4 瞬息宇宙 2026-08-10 4/200 2026-08-11 02:02 by 旁观2020
[基金申请] 确定了,国自然21号放榜 +6 布布和一二 2026-08-10 7/350 2026-08-10 19:15 by 2000zf36392
[基金申请] 综述论文作为代表作会不会影响评审专家的印象分? +10 yufeiwaner 2026-08-09 11/550 2026-08-10 18:47 by yufeiwaner
[基金申请] 关于代码变化问题,想知道的进来 +17 且听虎啸 2026-08-07 24/1200 2026-08-10 18:35 by zhangduo2008
[基金申请] 我的国基提前知道中了,可是同事的操作让我实在接受不了,怎么会有这样的人 +8 家与远方 2026-08-10 11/550 2026-08-10 17:09 by 六两废铜
[基金申请] 关于Filecode分析方法 +3 majunge000 2026-08-10 3/150 2026-08-10 15:46 by lch2012
[基金申请] 国自然结果 +4 Vierhys 2026-08-10 8/400 2026-08-10 15:06 by Vierhys
[基金申请] 好奇怪的filecode +4 布布和一二 2026-08-08 5/250 2026-08-10 14:20 by 冰心玉壶晴
[基金申请] 这样的filecode谁见过 +11 布布和一二 2026-08-08 22/1100 2026-08-10 11:10 by wmfsnow
[基金申请] 面上项目filecode邪修 +5 西山十月 2026-08-09 7/350 2026-08-10 07:32 by 仁砚薪传
[基金申请] filecode与中标关系的预测 +5 布布和一二 2026-08-07 5/250 2026-08-09 16:15 by 袁向阳007
[基金申请] 关于豆爷回答的JTJC与%2F数量 +5 yang182083 2026-08-06 7/350 2026-08-08 18:29 by zhanghaozhu
[基金申请] 关于filecode +4 布布和一二 2026-08-07 7/350 2026-08-07 22:55 by zhanghaozhu
[基金申请] 固定端突然变了,今天 +6 archvillain 2026-08-06 10/500 2026-08-07 16:03 by 医学老男孩
[基金申请] 听说今天filecode变了 +24 布布和一二 2026-08-06 47/2350 2026-08-07 16:02 by zhiyanjiang
[基金申请] 大家散了吧,后缀研究没有意义,别浪费时间了,过好目前的每一天,不要焦虑 +5 Tide man 2026-08-06 7/350 2026-08-07 13:11 by 医学老男孩
[基金申请] filecode +14 等待解的谜 2026-08-06 19/950 2026-08-07 12:20 by wlwhappy
[基金申请] 求各位大神看下 100+6 hpkpkpkp 2026-08-05 33/1650 2026-08-06 14:49 by zhiyanjiang
[基金申请] 影响面上的因素 +8 布布和一二 2026-08-05 11/550 2026-08-06 10:41 by 宝贝虫子
信息提示
请填处理意见