Flatland
tween.h
1 /*
2  * ______ __ __ __
3  * /\ _ \ __ /\ \/\ \ /\ \__
4  * \ \ \L\ \ __ __ /\_\ \_\ \ \ \____ ___\ \ ,_\ ____
5  * \ \ __ \/\ \/\ \\/\ \ /'_` \ \ '__`\ / __`\ \ \/ /',__\
6  * \ \ \/\ \ \ \_/ |\ \ \/\ \L\ \ \ \L\ \/\ \L\ \ \ \_/\__, `\
7  * \ \_\ \_\ \___/ \ \_\ \___,_\ \_,__/\ \____/\ \__\/\____/
8  * \/_/\/_/\/__/ \/_/\/__,_ /\/___/ \/___/ \/__/\/___/
9  * @copyright Copyright 2017 Avidbots Corp.
10  * @name tween.h
11  * @brief Tween plugin
12  * @author Joseph Duchesne
13  *
14  * Software License Agreement (BSD License)
15  *
16  * Copyright (c) 2017, Avidbots Corp.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions
21  * are met:
22  *
23  * * Redistributions of source code must retain the above copyright
24  * notice, this list of conditions and the following disclaimer.
25  * * Redistributions in binary form must reproduce the above
26  * copyright notice, this list of conditions and the following
27  * disclaimer in the documentation and/or other materials provided
28  * with the distribution.
29  * * Neither the name of the Avidbots Corp. nor the names of its
30  * contributors may be used to endorse or promote products derived
31  * from this software without specific prior written permission.
32  *
33  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
36  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
38  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
39  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
40  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
43  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44  * POSSIBILITY OF SUCH DAMAGE.
45  */
46 
47 #include <Box2D/Box2D.h>
48 #include <flatland_plugins/update_timer.h>
49 #include <flatland_server/model_plugin.h>
50 #include <flatland_server/timekeeper.h>
51 #include <flatland_server/types.h>
52 #include <geometry_msgs/Twist.h>
53 #include <nav_msgs/Odometry.h>
54 #include <std_msgs/Bool.h>
55 #include "tweeny.h"
56 
57 #ifndef FLATLAND_PLUGINS_TWEEN_H
58 #define FLATLAND_PLUGINS_TWEEN_H
59 
60 using namespace flatland_server;
61 
62 namespace flatland_plugins {
63 
65  public:
66  Body* body_; // The body this plugin is attached to
67  Pose start_; // The start pose of the model
68  Pose delta_; // The maximum change
69  float duration_; // Seconds to enact change over
70 
71  ros::Subscriber trigger_sub_; // Handle forward/reverse trigger
72  bool triggered_ = false; // If true,animate forwards, otherwise backwards
73 
74  tweeny::tween<double, double, double> tween_; // The tween object (x,y,theta)
75 
76  // The three different operating modes
77  enum class ModeType_ {
78  YOYO, // tween up to delta_, then down again, and repeat
79  LOOP, // tween up to delta_, then teleport back to start_
80  ONCE, // tween up to delta_ then stay there
81  TRIGGER // tween forwards on "true", backward on "false"
82  };
83  ModeType_ mode_;
84  static std::map<std::string, Tween::ModeType_> mode_strings_;
85 
86  enum class EasingType_ {
87  linear,
88  quadraticIn,
89  quadraticOut,
90  quadraticInOut,
91  cubicIn,
92  cubicOut,
93  cubicInOut,
94  quarticIn,
95  quarticOut,
96  quarticInOut,
97  quinticIn,
98  quinticOut,
99  quinticInOut,
100  // sinuisodal,
101  exponentialIn,
102  exponentialOut,
103  exponentialInOut,
104  circularIn,
105  circularOut,
106  circularInOut,
107  backIn,
108  backOut,
109  backInOut,
110  elasticIn,
111  elasticOut,
112  elasticInOut,
113  bounceIn,
114  bounceOut,
115  bounceInOut
116  };
117  static std::map<std::string, Tween::EasingType_> easing_strings_;
118 
124  void OnInitialize(const YAML::Node& config) override;
130  void BeforePhysicsStep(const Timekeeper& timekeeper) override;
131 
137  void TriggerCallback(const std_msgs::Bool& msg);
138 };
139 };
140 
141 #endif
Definition: dummy_model_plugin.h:59
Definition: body.h:55
Definition: types.h:84
Definition: timekeeper.h:55
Definition: model_plugin.h:64
Definition: body.h:61
Definition: tween.h:64