Skip to content

Commit 4bff9f5

Browse files
authored
Merge pull request #3 from jwithelm/feature/add_simulink_library_block
Feature/add simulink library block
2 parents 87d793d + f5115c2 commit 4bff9f5

6 files changed

Lines changed: 164 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### 1.2.1 (Jan 12, 2023)
2+
* Added Simulink library for HebiJoystick
3+
14
### 1.2 (Jan 26, 2017)
25
* Added support for keyboards
36
* Changed project name from HebiJoystick to MatlabInput

pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<modelVersion>4.0.0</modelVersion>
77

88
<groupId>us.hebi.matlab</groupId>
9-
<version>1.3-SNAPSHOT</version>
109
<artifactId>input</artifactId>
10+
<version>1.2.1</version>
1111

1212
<name>matlab-input</name>
1313
<description>MATLAB library for joystick and keyboard input</description>
@@ -27,6 +27,12 @@
2727
</developer>
2828
</developers>
2929

30+
<contributors>
31+
<contributor>
32+
<name>Jonas Withelm</name>
33+
</contributor>
34+
</contributors>
35+
3036
<scm>
3137
<url>https://github.com/HebiRobotics/MatlabInput</url>
3238
<connection>scm:git:git://github.com/HebiRobotics/MatlabInput.git</connection>
@@ -158,4 +164,4 @@
158164
</plugins>
159165
</build>
160166

161-
</project>
167+
</project>

src/main/assembly/release.xml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
12
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
23
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
34
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
@@ -7,18 +8,31 @@
78
<format>tar.gz</format>
89
<format>dir</format>
910
</formats>
10-
<includeBaseDirectory>false</includeBaseDirectory>
11+
<includeBaseDirectory>true</includeBaseDirectory>
1112
<fileSets>
13+
<!-- Copy Readme, License -->
14+
<fileSet>
15+
<directory>${project.basedir}/</directory>
16+
<includes>
17+
<include>README*</include>
18+
<include>LICENSE*</include>
19+
</includes>
20+
</fileSet>
1221
<!-- Copy backing MATLAB scripts -->
1322
<fileSet>
1423
<directory>${project.build.directory}/classes/matlab/</directory>
15-
<outputDirectory>hebi/</outputDirectory>
24+
<outputDirectory>matlab/</outputDirectory>
1625
<lineEnding>dos</lineEnding>
1726
</fileSet>
27+
<!-- Copy backing Simulink scripts -->
28+
<fileSet>
29+
<directory>${project.build.directory}/classes/simulink/</directory>
30+
<outputDirectory>simulink/</outputDirectory>
31+
</fileSet>
1832
<!-- Copy Java library (includes all Java dependencies) -->
1933
<fileSet>
20-
<directory>${project.build.directory}</directory>
21-
<outputDirectory>hebi/</outputDirectory>
34+
<directory>${project.build.directory}/</directory>
35+
<outputDirectory>matlab/</outputDirectory>
2236
<includes>
2337
<include>${releaseName}.jar</include>
2438
</includes>
@@ -27,7 +41,7 @@
2741
<dependencySets>
2842
<!-- Copy native binaries into lib directory -->
2943
<dependencySet>
30-
<outputDirectory>hebi/lib/</outputDirectory>
44+
<outputDirectory>matlab/lib/</outputDirectory>
3145
<useProjectArtifact>true</useProjectArtifact>
3246
<unpack>true</unpack>
3347
<scope>provided</scope>
@@ -37,7 +51,3 @@
3751
</dependencySet>
3852
</dependencySets>
3953
</assembly>
40-
41-
42-
43-
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
function hebijoyinput(block)
2+
% hebijoyinput is a HebiJoystick implementation for Simulink
3+
%
4+
% hebijoyinput is an alternative to MathWorks's 'Joystick Input'
5+
% block from 'Simulink 3D Animation' toolbox. 'hebijoyinput' is based
6+
% on 'HebiJoystick'. 'Simulink 3D Animation' toolbox is not required
7+
% for usage!
8+
%
9+
% See also:
10+
% HebiJoystick (https://github.com/HebiRobotics/MatlabInput)
11+
% Level-2 MATLAB S-Function (msfuntmpl)
12+
13+
% Copyright (c) 2023 Jonas Withelm
14+
% SPDX-License-Identifier: Apache-2.0
15+
16+
setup(block);
17+
18+
%endfunction
19+
20+
21+
function setup(block)
22+
23+
%% Register number of dialog parameters
24+
block.NumDialogPrms = 3; % joyid
25+
block.DialogPrmsTunable = {'Nontunable','Nontunable','Nontunable'}; % not tunable during simulation
26+
27+
%% Setup joystick
28+
joyid = block.DialogPrm(1).Data;
29+
forcefeed = block.DialogPrm(3).Data;
30+
31+
% initialize joystick
32+
joy = HebiJoystick(joyid);
33+
34+
% read capabilities of joystick
35+
caps = joy.caps();
36+
37+
% store persistent data
38+
set_param(block.BlockHandle,'UserData',joy);
39+
40+
%% Register number of output ports
41+
block.NumOutputPorts = 2;
42+
43+
%% Register number of input ports
44+
if forcefeed && (caps.Forces > 0)
45+
block.NumInputPorts = 1;
46+
else
47+
block.NumInputPorts = 0;
48+
end
49+
50+
%% Set up the port properties to be inherited or dynamic
51+
block.SetPreCompInpPortInfoToDynamic;
52+
block.SetPreCompOutPortInfoToDynamic;
53+
54+
%% Set the output port properties
55+
block.OutputPort(1).DimensionsMode = 'Fixed';
56+
block.OutputPort(1).SamplingMode = 'sample';
57+
block.OutputPort(1).Dimensions = caps.Axes;
58+
block.OutputPort(1).DatatypeID = 0; % double
59+
block.OutputPort(1).Complexity = 'Real';
60+
61+
block.OutputPort(2).DimensionsMode = 'Fixed';
62+
block.OutputPort(2).SamplingMode = 'sample';
63+
block.OutputPort(2).Dimensions = caps.Buttons;
64+
block.OutputPort(2).DatatypeID = 0; % double
65+
block.OutputPort(2).Complexity = 'Real';
66+
67+
if forcefeed && (caps.Forces > 0)
68+
block.InputPort(1).DimensionsMode = 'Fixed';
69+
block.InputPort(1).SamplingMode = 'sample';
70+
block.InputPort(1).Dimensions = caps.Forces;
71+
block.InputPort(1).DatatypeID = 0; % double
72+
block.InputPort(1).Complexity = 'Real';
73+
block.InputPort(1).DirectFeedthrough = false;
74+
end
75+
76+
%% Set up the continuous states
77+
block.NumContStates = 0;
78+
79+
%% Set block sample time
80+
block.SampleTimes = [1/50 0]; % Discrete sample time (50 Hz)
81+
82+
%% Set the block simStateCompliance to default (i.e., same as a built-in block)
83+
block.SimStateCompliance = 'DefaultSimState';
84+
85+
%% Register methods
86+
block.RegBlockMethod('Outputs', @Outputs);
87+
block.RegBlockMethod('Terminate', @Terminate);
88+
89+
%endfunction
90+
91+
92+
function Outputs(block)
93+
94+
joy = get_param(block.BlockHandle,'UserData');
95+
96+
caps = joy.caps();
97+
98+
% read force feedback from block input and send to joystick
99+
forcefeed = block.DialogPrm(3).Data;
100+
if forcefeed && (caps.Forces > 0)
101+
for idx=1:caps.Forces
102+
joy.force(idx, block.InputPort(idx).Data);
103+
end
104+
end
105+
106+
% read axes and buttons from joystick and write to block outputs
107+
[axes, buttons, ~] = joy.read();
108+
109+
block.OutputPort(1).Data = axes;
110+
block.OutputPort(2).Data = buttons;
111+
112+
%endfunction
113+
114+
115+
function Terminate(block)
116+
117+
joy = get_param(block.BlockHandle,'UserData');
118+
119+
joy.close();
120+
121+
%endfunction
26.5 KB
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function blkStruct = slblocks
2+
% This function specifies that the library 'matlabinput_lib'
3+
% should appear in the Library Browser with the
4+
% name 'MatlabInput'
5+
6+
Browser.Library = 'matlabinput_lib';
7+
% 'matlabinput_lib' is the name of the library
8+
9+
Browser.Name = 'MatlabInput';
10+
% 'MatlabInput' is the library name that appears
11+
% in the Library Browser
12+
13+
blkStruct.Browser = Browser;

0 commit comments

Comments
 (0)