Main Page · Modules · All Classes · Class Hierarchy
MARobotStateUpdater.cpp
1 /*
2  * This file is part of the AiBO+ project
3  *
4  * Copyright (C) 2005-2016 Csaba Kertész (csaba.kertesz@gmail.com)
5  *
6  * AiBO+ is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * AiBO+ is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
19  *
20  */
21 
22 #include "MARobotStateUpdater.hpp"
23 
24 #include "MABodyMotion.hpp"
25 #include "MARobotState.hpp"
26 
27 #include <MCLog.hpp>
28 
29 namespace
30 {
31 // Robot state updater pointer list type
32 typedef std::vector<MARobotStateUpdater*> RobotStateUpdaterList;
33 
35 }
36 
37 MARobotStateUpdater::MARobotStateUpdater(MA::RobotStateUpdateType update_type) :
38  UpdateType(update_type)
39 {
40 }
41 
42 
44 {
45  if (likely(!Updaters.get()))
46  return;
47 
48  // Remove the current instance from the global updater list if presented
49  for (auto iter = Updaters->begin(); iter != Updaters->end(); ++iter)
50  {
51  if (*iter == this)
52  {
53  Updaters->erase(iter);
54  break;
55  }
56  }
57 }
58 
59 
61 {
62  if (likely(!Updaters.get()))
63  {
64  Updaters.reset(new RobotStateUpdaterList);
65  }
66  const auto Iter = std::find(Updaters->begin(), Updaters->end(), &updater);
67 
68  if (Iter == Updaters->end())
69  {
70  // Add the current instance to the global updater list
71  Updaters->push_back(&updater);
72  }
73 }
74 
75 
77 {
78  if (unlikely(!Updaters.get()))
79  return;
80 
81  RobotStateUpdaterList& UpdaterList = *Updaters.get();
82 
83  // Reset the skit playback
84  state.BodyMotion->SkitPlayback = 0;
85  // Sensor data updates
86  for (auto& updater : UpdaterList)
87  {
88  if (updater->UpdateType == MA::UpdateSensorData)
89  {
90  updater->UpdateRobotState(state);
91  }
92  }
93  // Sensor indicator updates
94  for (auto& updater : UpdaterList)
95  {
96  if (updater->UpdateType == MA::UpdateSensorIndicators)
97  updater->UpdateRobotState(state);
98  }
99  // Global indicator updates
100  for (auto& updater : UpdaterList)
101  {
102  if (updater->UpdateType == MA::UpdateComplexIndicators)
103  updater->UpdateRobotState(state);
104  }
105 }
MARobotStateUpdater(MA::RobotStateUpdateType update_type)
Struct constructor.
static void RegisterUpdater(MARobotStateUpdater &updater)
Register a robot state updater.
boost::scoped_ptr< MABodyMotion > BodyMotion
Body motion.
Robot state updater base class.
A wrapper class to cover boost::thread_specific_ptr/folly::ThreadLocal API on certain targets...
static void Run(MARobotState &state)
Run the robot state updates.
virtual ~MARobotStateUpdater()
Struct destructor.
Robot state.