Main Page · Modules · All Classes · Class Hierarchy
MALegController.hpp
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 #pragma once
23 
24 #include "types/MABodyTypes.hpp"
25 #include "types/MALeg.hpp"
26 #include "MAController.hpp"
27 
28 #include <MCThreadLocalData.hpp>
29 
30 #include <boost/shared_ptr.hpp>
31 
32 class MADevice;
33 class MAGeneratorBase;
34 class MALegController;
35 class MARobotState;
36 
42 namespace MA
43 {
52 }
53 
56 {
57  MALegTransitionGenerators() : Joint1(nullptr), Joint2(nullptr), Joint3(nullptr)
58  { }
59 
60  void AddGeneratorToJoint1(MAGeneratorBase& generator);
61  void AddGeneratorToJoint2(MAGeneratorBase& generator);
62  void AddGeneratorToJoint3(MAGeneratorBase& generator);
63  void AlignDurations();
64 
65  MAGeneratorContainer* Joint1;
66  MAGeneratorContainer* Joint2;
67  MAGeneratorContainer* Joint3;
68 };
69 
74 {
75 public:
76  explicit MALegController(MA::Leg::LegTypes leg);
77  virtual ~MALegController();
78 
79 private:
80  virtual void UpdateRobotState(MARobotState& state) override;
81 
82 public:
83  virtual MA::DeviceList GetMotors() const override;
84  void SetPower(MA::LegJointsType joint, bool new_state);
85  void SetPower(bool new_state);
86  bool IsPowerOn(MA::LegJointsType joint) const;
87  bool IsPowerOn() const;
88  bool IsMoving() const;
89  void Stop();
90  MA_DECLARE_TRANSITION(Pull, IsPulled)
91  MA_DECLARE_TRANSITION(SwingForTurnOver, IsSwungForTurnOver)
92  MA_DECLARE_TRANSITION(ToLyingPosition, IsLyingPosition)
93  MA_DECLARE_TRANSITION(MoveAway, IsMovedAway)
94  MA_DECLARE_TRANSITION_ACTION(MoveAwayBackward)
95  MA_DECLARE_TRANSITION_ACTION(MoveAwayFirstUp)
96  MA_DECLARE_TRANSITION(ToSittingPosition, IsSittingPosition)
97  MA_DECLARE_TRANSITION_ACTION(WalkSwingForward)
98  MA_DECLARE_TRANSITION_ACTION(WalkPushBackward)
99  MA_DECLARE_TRANSITION_ACTION(WalkSwingBackward)
100  MA_DECLARE_TRANSITION_ACTION(WalkPushForward)
101  MA_DECLARE_TRANSITION(ToInitialWalkPosition, IsInitialWalkPosition)
102  MA_DECLARE_TRANSITION_ACTION(BalanceToCenter)
103  MA_DECLARE_TRANSITION_ACTION(BalanceToLeft)
104  MA_DECLARE_TRANSITION_ACTION(BalanceToRight)
105  MA_DECLARE_TRANSITION_ACTION(AdjustStandingPosture)
106  bool IsAhead() const;
107  bool IsBack() const;
108  void PrintFeatures();
109 
110 protected:
111  MADevice* GetDevice(const MABodyPartFeature& body_part) const;
112  void RegisterDeviceUpdates();
113  void NotifyDeviceUpdate(MADevice& device);
114  void CreateGenerators(MALegTransitionGenerators& generators, const MABodyPartFeature& target, int msec);
115  virtual MA::DeviceGeneratorsMap GetSkitTransitionGenerators(MA::SkitBaseSPtr skit) override;
116  MA::DeviceGeneratorsMap ApplyGenerators(MALegTransitionGenerators& generators, bool clear = false);
117 
118 public:
119  inline MA::Leg::LegTypes GetLegType() const
120  {
121  return LegType;
122  }
123 
124 protected:
126  MA::Leg::LegTypes LegType;
128  boost::shared_ptr<MADevice> Joint1;
130  boost::shared_ptr<MADevice> Joint2;
132  boost::shared_ptr<MADevice> Joint3;
134  boost::shared_ptr<MADevice> Paw;
135  /*
136  * Forward-backward and upward-downward direction
137  * -100 - backward 100 - forward
138  * -100 - downward 100 - upward
139  */
140  MALegPosition Position;
141  /*
142  * Sidelong direction
143  * 0 - least 100 - full
144  */
145  MASidelong Sidelong;
146  /*
147  * Bent-stretched state
148  * 0 - full stretched 100 - full bent
149  */
150  MABentStretched BentStretched;
151 };
152 
Helper class to build leg transition generators.
boost::shared_ptr< MADevice > Joint1
First joint.
The forward-backward/upward-downward feature of a leg joint.
Definition: MABodyTypes.hpp:92
boost::shared_ptr< MADevice > Joint2
Second joint.
Base class for the controllers.
Device class.
Definition: MADevice.hpp:57
MA::Leg::LegTypes LegType
Leg descriptor.
A base class for the limb features.
Definition: MABodyTypes.hpp:56
Leg controller class.
boost::shared_ptr< MADevice > Paw
Paw sensor.
The bent-stretched feature of a leg joint.
Generator container class.
The sidelong feature of a leg joint.
Base class for generators.
A wrapper class to cover boost::thread_specific_ptr/folly::ThreadLocal API on certain targets...
Robot state.
boost::shared_ptr< MADevice > Joint3
Third joint.