Main Page · Modules · All Classes · Class Hierarchy
MATorsoController.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 "MATorsoController.hpp"
23 
24 #include "core/MADevice.hpp"
25 #include "types/MABodyMotion.hpp"
26 #include "types/MARobotState.hpp"
27 #include "types/MATorso.hpp"
28 #include "types/MATypeRanges.hpp"
29 
30 #include <MCLog.hpp>
31 
32 #include <boost/math/constants/constants.hpp>
33 
34 namespace MA
35 {
37 }
38 
40 {
41  if (MA::Torso.get())
42  {
43  MC_WARNING("The global torso controller is overridden.");
44  }
45  MA::Torso.reset(this);
46 }
47 
48 
50 {
51  if (MA::Torso.get() == this)
52  MA::Torso.release();
53 }
54 
55 
57 {
58  float Pi = boost::math::constants::pi<float>();
59 
60  state.Torso->BackButtonF = (int)BackFButton->GetSensorValue();
61  state.Torso->BackButtonM = (int)BackMButton->GetSensorValue();
62  state.Torso->BackButtonR = (int)BackRButton->GetSensorValue();
63  state.BodyMotion->AccelX.Raw = (int)(AccelX->GetSensorValue() / 100.0);
64  SetAccelRawHighresValues(state.BodyMotion->AccelX.Raw, *AccelX);
65  state.BodyMotion->AccelY.Raw = (int)(AccelY->GetSensorValue() / 100.0);
66  SetAccelRawHighresValues(state.BodyMotion->AccelY.Raw, *AccelY);
67  state.BodyMotion->AccelZ.Raw = (int)(AccelZ->GetSensorValue() / 100.0);
68  SetAccelRawHighresValues(state.BodyMotion->AccelZ.Raw, *AccelZ);
69  state.BodyMotion->AccelX.Degree = (int)(atan(AccelX->GetSensorValue() / 1000000.0)*180.0 / Pi);
70  SetAccelDegreeHighresValues(state.BodyMotion->AccelX.Degree, *AccelX);
71  state.BodyMotion->AccelY.Degree = (int)(atan(AccelY->GetSensorValue() / 1000000.0)*180.0 / Pi);
72  SetAccelDegreeHighresValues(state.BodyMotion->AccelY.Degree, *AccelY);
73  state.BodyMotion->AccelZ.Degree = (int)(atan(AccelZ->GetSensorValue() / 1000000.0)*180.0 / Pi);
74  SetAccelDegreeHighresValues(state.BodyMotion->AccelZ.Degree, *AccelZ);
75  state.Torso->ChestIR = (int)InfraChest->GetSensorValue();
76  state.Torso->NearIR = (int)InfraNear->GetSensorValue();
77  state.Torso->FarIR = (int)InfraFar->GetSensorValue();
78  state.Torso->FreeMemory = GetFreeMemory();
79 }
80 
81 
82 MA::DeviceGeneratorsMap MATorsoController::GetSkitTransitionGenerators(MA::SkitBaseSPtr)
83 {
84  return MA::DeviceGeneratorsMap();
85 }
86 
87 
88 void MATorsoController::SetAccelRawHighresValues(MANum<int>& value, MADevice& device) const
89 {
90  MC::IntList NewValues;
91  const MC::FloatList& OriginalValues = device.GetRealSensorValues();
92 
93  for (auto& value : OriginalValues)
94  {
95  NewValues.push_back((int)(value / 100));
96  }
97  value.SetHighResolutionValues(NewValues);
98 }
99 
100 
101 void MATorsoController::SetAccelDegreeHighresValues(MANum<int>& value, MADevice& device) const
102 {
103  MC::IntList NewValues;
104  const MC::FloatList& OriginalValues = device.GetRealSensorValues();
105 
106  for (auto& value : OriginalValues)
107  {
108  NewValues.push_back((int)(atan((value)/ 1000000.0)*180.0 / boost::math::constants::pi<float>()));
109  }
110  value.SetHighResolutionValues(NewValues);
111 }
112 
113 
114 MA::DeviceList MATorsoController::GetMotors() const
115 {
116  return MA::DeviceList();
117 }
118 
119 
120 void MATorsoController::RequestRestart()
121 {
122  // Nothing to do here
123 }
124 
125 
126 void MATorsoController::RequestShutdown()
127 {
128  // Nothing to do here
129 }
130 
131 
132 void MATorsoController::RequestDebugMode()
133 {
134  // Nothing to do here
135 }
136 
137 
138 int MATorsoController::GetFreeMemory() const
139 {
140  // Nothing to do here
141  return 0;
142 }
boost::scoped_ptr< MADevice > BackFButton
Touchsensor on the back (fore)
boost::scoped_ptr< MADevice > InfraNear
Infrared sensor (near)
boost::scoped_ptr< MADevice > BackMButton
Touchsensor on the back (middle)
boost::scoped_ptr< MADevice > AccelX
Accelerometer sensor (X dimension)
virtual void UpdateRobotState(MARobotState &state) override
Update the robot state.
boost::scoped_ptr< MADevice > InfraChest
Infrared sensor (chest)
#define MC_WARNING(...)
Warning macro.
Definition: MCLog.hpp:43
Base class for the controllers.
Device class.
Definition: MADevice.hpp:57
boost::scoped_ptr< MADevice > AccelZ
Accelerometer sensor (Z dimension)
boost::scoped_ptr< MADevice > InfraFar
Infrared sensor (far)
virtual MA::DeviceGeneratorsMap GetSkitTransitionGenerators(MA::SkitBaseSPtr skit) override
Get skit transition generators.
virtual MA::DeviceList GetMotors() const override
Get the list of the motors.
MATorsoController()
Class constructor.
boost::scoped_ptr< MABodyMotion > BodyMotion
Body motion.
boost::scoped_ptr< MADevice > AccelY
Accelerometer sensor (Y dimension)
boost::scoped_ptr< MADevice > BackRButton
Touchsensor on the back (rear)
A wrapper class to cover boost::thread_specific_ptr/folly::ThreadLocal API on certain targets...
void SetHighResolutionValues(const std::vector< T > &new_highres_values)
Set high resolution values.
Definition: MANum.hpp:144
boost::scoped_ptr< MATorso > Torso
Torso.
Robot state.
virtual ~MATorsoController()
Class destructor.