-
Notifications
You must be signed in to change notification settings - Fork 0
/
InitializeRobot.m
62 lines (55 loc) · 1.96 KB
/
InitializeRobot.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
% Robot = InitializeRobot(Class,Position,Name,Orientation,RobotProfile)
% Amirkabir University of Tehran (Tehran Polytechnic)
% Summer 2011
% http://www.mechatronics3d.com
function Robot = InitializeRobot(Class,Position,Name,Orientation,RobotProfile)
Defaults={'TeleMax',[0,0.1,1.8],'MyRobot',[0,0,1.5708],0};
% %Some where I Read that in y position of zero USARSim has a bug!
if nargin > 2
if Position(2)==0
Position(2)=0.1;
end
end
if nargin > 5
error('Too many input arguments');
elseif nargin == 5
Robot.Name=Name;
Robot.Class=Class;
elseif nargin == 4
RobotProfile=Defaults{5};
Robot.Name=Name;
Robot.Class=Class;
elseif nargin == 3
RobotProfile=Defaults{5};
Orientation=Defaults{4};
Robot.Name=Name;
Robot.Class=Class;
elseif nargin == 2
RobotProfile=Defaults{5};
Orientation=Defaults{4};
Robot.Name=Defaults{3};
Robot.Class=Class;
elseif nargin == 1
RobotProfile=Defaults{5};
Orientation=Defaults{4};
Robot.Name=Defaults{3};
Position=Defaults{2};
Robot.Class=Class;
else
RobotProfile=Defaults{5};
Orientation=Defaults{4};
Robot.Name=Defaults{3};
Position=Defaults{2};
Robot.Class=Defaults{1};
end
Robot.Connection=tcpip('localhost', 3000,'Terminator',{'CR/LF','CR/LF'},'inputbuffersize',4096);
fopen(Robot.Connection);
set(Robot.Connection,'ReadAsyncMode','manual');
fprintf(Robot.Connection,['INIT {ClassName USARBot.' Robot.Class '} ' ...
'{Name ' Robot.Name '} ' ...
'{Location ' num2str(Position(1)) ',' num2str(Position(2)) ',' num2str(Position(3)) '} ' ...
'{Rotation ' num2str(Orientation(1)) ',' num2str(Orientation(2)) ',' num2str(Orientation(3)) '}']);
if RobotProfile
path='C:/UT2004';
Robot=AddRobotProfile(Robot,path);
end