Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TDDE19-group-5-pepper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TDDE19-2021-5
TDDE19-group-5-pepper
Commits
82ffabc0
Commit
82ffabc0
authored
3 years ago
by
Simon Wijk Stranius
Browse files
Options
Downloads
Patches
Plain Diff
6: Add simple states for finding people
parent
1f63f317
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lhw_intelligence/lhw_intelligence/states/emotional_pepper.py
+71
-9
71 additions, 9 deletions
..._intelligence/lhw_intelligence/states/emotional_pepper.py
with
71 additions
and
9 deletions
src/lhw_intelligence/lhw_intelligence/states/emotional_pepper.py
+
71
−
9
View file @
82ffabc0
from
.state
import
State
from
rclpy.node
import
Node
from
sensor_msgs.msg
import
Image
from
std_msgs.msg
import
String
from
lhw_interfaces.msg
import
Result
,
Entity
,
Entities
import
transitions
as
sm
import
rclpy
...
...
@@ -7,28 +10,87 @@ class EmotionalPepper(State):
states
=
[
"
look_for_persons
"
,
"
greet_person
"
,
"
recognize_person
"
,
"
remember_person
"
,
"
free_talk
"
,
"
analyse_emotion
"
,
"
emotion_verdict
"
]
# self.machine.add_transition(trigger='wake_up', source='asleep', dest='hanging out')
transitions
=
[
{
"
trigger
"
:
0
,
"
source
"
:
0
,
"
dest
"
:
0
}
]
def
__init__
(
self
,
node
,
args
=
[]):
super
().
__init__
(
node
,
args
)
self
.
name
=
node
.
get_name
()
self
.
node
=
node
self
.
machine
=
sm
.
Machine
(
model
=
self
,
states
=
EmotionalPepper
.
states
,
initial
=
"
look_for_persons
"
)
self
.
log
=
self
.
node
.
get_logger
()
self
.
machine
=
sm
.
Machine
(
model
=
self
,
states
=
EmotionalPepper
.
states
,
initial
=
"
dummy
"
)
self
.
to_look_for_persons
()
self
.
person_in_frame
=
False
self
.
machine
.
add_transition
(
"
trigger_found_person
"
,
"
look_for_persons
"
,
"
greet_person
"
)
self
.
machine
.
add_transition
(
"
trigger_recognize_person
"
,
"
greet_person
"
,
"
recognize_person
"
)
self
.
entities_sub
=
self
.
node
.
create_subscription
(
Entities
,
"
yolov5_entities
"
,
self
.
__entities_cb
,
1
)
self
.
run_timer
=
self
.
node
.
create_timer
(
2
,
self
.
__run
)
"""
enter/exit callbacks
"""
def
on_enter_greet_person
(
self
):
self
.
node
.
get_logger
().
info
(
"
Entering greet person
"
)
self
.
say
(
"
Hello Person
"
)
def
on_exit_greet_person
(
self
):
self
.
node
.
get_logger
().
info
(
"
Exiting greet person
"
)
def
on_enter_look_for_persons
(
self
):
self
.
log
.
info
(
"
Entering look_for_persons
"
)
self
.
say
(
"
Looking for persons
"
)
def
on_exit_look_for_persons
(
self
):
self
.
log
.
info
(
"
Exiting look_for_persons
"
)
def
on_enter_recognize_person
(
self
):
self
.
log
.
info
(
"
Entering recognize_person
"
)
self
.
say
(
"
Trying to recognize you...
"
)
"""
end callbacks
"""
def
__run
(
self
):
self
.
node
.
get_logger
().
info
(
"
Running State Machine Loop :)
"
)
#self.node.get_logger().info("Running State Machine Loop :)")
self
.
node
.
get_logger
().
info
(
f
"
In state:
{
self
.
state
}
"
)
if
self
.
state
==
"
greet_person
"
:
self
.
trigger_recognize_person
()
elif
self
.
state
==
"
look_for_persons
"
:
pass
elif
self
.
state
==
"
recognize_person
"
:
pass
else
:
self
.
say
(
"
Unknown state
"
)
def
__entities_cb
(
self
,
entities
):
#self.node.get_logger().info("Recevied entities! :D")
ents
=
entities
.
entities
found_person
=
False
for
e
in
ents
:
# lhw_interfaces.msg.Entity(id=0, sources_types=lhw_interfaces.msg.VisualSources(),
# sources=[], sources_ids=[], bbox=array([305, 331, 535, 479], dtype=int32), xyz=array([0., 0., 0.], dtype=float32), type='tv', confidence=0.67578125)
if
(
e
.
type
==
"
person
"
):
if
not
self
.
person_in_frame
:
self
.
node
.
get_logger
().
info
(
"
Found person!
"
)
self
.
person_in_frame
=
True
self
.
trigger_found_person
()
found_person
=
True
#self.node.get_logger().info(str(e))
if
not
found_person
:
self
.
person_in_frame
=
False
self
.
to_look_for_persons
()
class
StateMachineNode
(
Node
):
def
__init__
(
self
):
super
().
__init__
(
"
transitions_ros
"
)
# Node name
self
.
log
=
self
.
get_logger
()
self
.
say_publisher
=
self
.
create_publisher
(
String
,
'
say
'
,
100
)
self
.
machine
=
EmotionalPepper
(
self
)
...
...
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