Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sot-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stack Of Tasks
sot-core
Commits
94d0af53
Commit
94d0af53
authored
6 years ago
by
Joseph Mirabel
Committed by
Joseph Mirabel
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add entity Switch
parent
171862bc
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
include/CMakeLists.txt
+1
-0
1 addition, 0 deletions
include/CMakeLists.txt
include/sot/core/switch.hh
+118
-0
118 additions, 0 deletions
include/sot/core/switch.hh
src/CMakeLists.txt
+1
-0
1 addition, 0 deletions
src/CMakeLists.txt
src/tools/switch.cpp
+35
-0
35 additions, 0 deletions
src/tools/switch.cpp
with
155 additions
and
0 deletions
include/CMakeLists.txt
+
1
−
0
View file @
94d0af53
...
...
@@ -86,6 +86,7 @@ SET(NEWHEADERS
sot/core/periodic-call.hh
sot/core/periodic-call-entity.hh
sot/core/trajectory.hh
sot/core/switch.hh
)
INSTALL
(
FILES
${
NEWHEADERS
}
DESTINATION include/sot/core
...
...
This diff is collapsed.
Click to expand it.
include/sot/core/switch.hh
0 → 100644
+
118
−
0
View file @
94d0af53
// Copyright (c) 2018, Joseph Mirabel
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
//
// This file is part of sot-core.
// sot-core is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// sot-core is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// sot-core. If not, see <http://www.gnu.org/licenses/>.
#ifndef __SOT_SWITCH_H__
# define __SOT_SWITCH_H__
#include
<iostream>
#include
<dynamic-graph/entity.h>
#include
<dynamic-graph/signal.h>
#include
<dynamic-graph/signal-ptr.h>
#include
<dynamic-graph/signal-time-dependent.h>
#include
<dynamic-graph/pool.h>
#include
<dynamic-graph/command-bind.h>
#include
<dynamic-graph/command-getter.h>
#include
<sot/core/config.hh>
namespace
dynamicgraph
{
namespace
sot
{
/// Switch
template
<
typename
Value
,
typename
Time
=
int
>
class
SOT_CORE_DLLAPI
Switch
:
public
dynamicgraph
::
Entity
{
DYNAMIC_GRAPH_ENTITY_DECL
();
Switch
(
const
std
::
string
&
name
)
:
Entity
(
name
),
selectionSIN
(
NULL
,
"Switch("
+
name
+
")::input(int)::selection"
),
boolSelectionSIN
(
NULL
,
"Switch("
+
name
+
")::input(bool)::boolSelection"
),
signalSOUT
(
"Switch("
+
name
+
")::output("
+
typeName
()
+
")::sout"
)
{
signalSOUT
.
setFunction
(
boost
::
bind
(
&
Switch
::
signal
,
this
,
_1
,
_2
));
signalRegistration
(
selectionSIN
<<
boolSelectionSIN
<<
signalSOUT
);
using
command
::
makeCommandVoid1
;
std
::
string
docstring
=
"
\n
"
" Set number of input signals
\n
"
;
addCommand
(
"setSignalNumber"
,
makeCommandVoid1
(
*
this
,
&
Switch
::
setSignalNumber
,
docstring
));
}
~
Switch
()
{}
/// Header documentation of the python class
virtual
std
::
string
getDocString
()
const
{
return
"Dynamically select a given signal based on a input information.
\n
"
;
}
void
setSignalNumber
(
const
int
&
n
)
{
assert
(
n
>=
0
);
const
std
::
size_t
oldSize
=
signals
.
size
();
for
(
std
::
size_t
i
=
n
;
i
<
oldSize
;
++
i
)
{
std
::
ostringstream
oss
;
oss
<<
"sin"
<<
i
;
signalDeregistration
(
oss
.
str
());
delete
signals
[
i
];
}
signals
.
resize
(
n
,
NULL
);
for
(
std
::
size_t
i
=
oldSize
;
i
<
(
std
::
size_t
)
n
;
++
i
)
{
assert
(
signals
[
i
]
==
NULL
);
std
::
ostringstream
oss
;
oss
<<
"Switch("
<<
getName
()
<<
")::input("
<<
typeName
()
<<
")::sin"
<<
i
;
signals
[
i
]
=
new
Signal_t
(
NULL
,
oss
.
str
());
signalRegistration
(
*
signals
[
i
]);
}
}
private
:
typedef
SignalPtr
<
Value
,
Time
>
Signal_t
;
typedef
std
::
vector
<
Signal_t
*>
Signals_t
;
static
const
std
::
string
&
typeName
();
Value
&
signal
(
Value
&
ret
,
const
Time
&
time
)
{
int
sel
;
if
(
selectionSIN
.
isPlugged
())
{
sel
=
selectionSIN
(
time
);
}
else
{
const
bool
&
b
=
boolSelectionSIN
(
time
);
sel
=
b
?
1
:
0
;
}
if
(
sel
<
0
||
sel
>=
int
(
signals
.
size
()))
throw
std
::
runtime_error
(
"Signal selection is out of range."
);
ret
=
(
*
signals
[
sel
])
(
time
);
return
ret
;
}
Signals_t
signals
;
SignalPtr
<
int
,
Time
>
selectionSIN
;
SignalPtr
<
bool
,
Time
>
boolSelectionSIN
;
Signal
<
Value
,
Time
>
signalSOUT
;
};
}
// namespace sot
}
// namespace dynamicgraph
#endif // __SOT_SWITCH_H__
This diff is collapsed.
Click to expand it.
src/CMakeLists.txt
+
1
−
0
View file @
94d0af53
...
...
@@ -92,6 +92,7 @@ SET(plugins
tools/periodic-call-entity
tools/joint-trajectory-entity
tools/latch
tools/switch
control/control-gr
control/control-pd
...
...
This diff is collapsed.
Click to expand it.
src/tools/switch.cpp
0 → 100644
+
35
−
0
View file @
94d0af53
// Copyright (c) 2017, Joseph Mirabel
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
//
// This file is part of sot_hpp.
// sot_hpp is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// sot_hpp is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// sot_hpp. If not, see <http://www.gnu.org/licenses/>.
#include
<sot/core/switch.hh>
#include
<dynamic-graph/factory.h>
#include
"type-name-helper.hh"
namespace
dynamicgraph
{
namespace
sot
{
template
<
typename
Value
,
typename
Time
>
const
std
::
string
&
Switch
<
Value
,
Time
>::
typeName
()
{
return
TypeNameHelper
<
Value
>::
typeName
;
}
typedef
Switch
<
Vector
,
int
>
SwitchVector
;
template
<
>
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
(
SwitchVector
,
"SwitchVector"
);
}
// namespace sot
}
// namespace dynamicgraph
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment