Hi,
in this ( https://www.youtube.com/watch?v=FrpG-KP_Tg8 ) video at the end, a transformation is applied. I have adopted the code from the video, but somehow my axes get scaled too. This is my code:
clc;close all;clear all;comPort = '/dev/cu.usbmodem1421';if(~exist('serialFlag','var')); [fsr.s,serialFlag] = setupSerial(comPort);endif(~exist('h','var')|| ~ishandle(h)) h = figure(1);endif(~exist('text1','var')) text1 = uicontrol('Style','text', 'String', 'X: 0 degress',... 'pos',[450 100 100 25],'parent',h);endif(~exist('text2','var')) text2 = uicontrol('Style','text', 'String', 'Y: 0 degress',... 'pos',[450 75 100 25],'parent',h);endif(~exist('button','var')) button = uicontrol('Style','togglebutton', 'String', 'Stop & Close Serial Port',... 'pos',[0 0 200 25],'parent',h);endweights=[0 700 800 900 1000 1500 2000 2500 3000 4000 4999];%Hier noch mehr hinzufuegen
m1 = zeros(length(weights),1);length(weights)%Read values for each weight and assign it
for i=2:length(weights) mbox = msgbox(['Place ' num2str(weights(i)) ' grams on FSR.']); uiwait(mbox); m1(i)= readFSR(fsr) while (m1(i)<m1(i-1)) m1(i)=readFSR(fsr); end end m=m1.'; P1=polyfit(m,weights,2) %250 is the max weight. 250g. Change to 20 000!
myaxes = axes('xlim',[-20 20],'ylim',[-20 20],'zlim',[0 6]); view(3); grid on; axis equal; hold on;%Draw sphere
[xsphere, ysphere, zsphere] = sphere();h(1) = surface(xsphere,ysphere,zsphere);combinedobject = hgtransform('parent',myaxes);set(h,'parent',combinedobject)drawnowwhile (get(button,'Value')==0) [voltage]=readFSR(fsr); mass = polyval(P1,voltage); %in g
if(mass>0) force = mass*9.81; %in newton
set(text1,'String',['Mass: ' num2str(mass) ' g']); set(text2,'String',['Force: ' num2str(force) ' N']); translation = makehgtform('translate',[0 0 mass/1000]); %in kg's
set(combinedobject,'matrix',translation); %Scale sphere
scaling = makehgtform('scale', mass/10000); set(combinedobject,'matrix',scaling); set(combinedobject,'matrix',translation*scaling); drawnow end pause(0.1); end closeSerial;
Best Answer