10#ifndef MOTION_Interface_DEFINED
11#define MOTION_Interface_DEFINED
12#define MOTION_Commands_DEFINED
13#define MOTION_Status_DEFINED
15#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
26#pragma clang diagnostic push
27#pragma clang diagnostic ignored "-Wpadded"
29#define MOTION_DIR "/data/motions/"
30#define MOTION_FILE_POSTFIX ".mot"
31#define JOINT_CHAIN_MAXSIZE 10
32#define CHAIN_IGNORED_MOTION_DURATION 100
33#define TRANSITION_NAME(s, e) TRANSITION_NAME_FROM_STRING(stance_strings[s], stance_strings[e])
34#define TRANSITION_NAME_FROM_STRING(s, e) ((((std::string("transition_") += s) += "_") += e) += MOTION_FILE_POSTFIX)
35#define ACTION_NAME(a, s) ((((std::string("action_") += stance_strings[s]) += "_") += action_strings[a]) += MOTION_FILE_POSTFIX)
36#define STANCE_NAME(s) STANCE_NAME_FROM_STRING(stance_strings[s])
37#define STANCE_NAME_FROM_STRING(s) std::string("stance_").append(std::string(s).append(MOTION_FILE_POSTFIX))
39#define MAP_ACTION_ENTRY(a, s, c) v[a] = Action_Transition(a, s, c);
41#define MY_CHECK_ENUM(s,p,v) if (strstr((s), #v)) p = v
101 "GoalieSaveLeft_stance",
102 "GoalieSaveRight_stance",
103 "FallenForward_stance",
113 "Kneeling_quickwave",
115 "Kneeling_raiseright",
118 "Standing_rightkick",
120 "Standing_rightpass",
147 std::vector<Stance_Transition> v;
190 std::map<action, Action_Transition> v;
205 static const std::map<action, Action_Transition>
_actions;
229 bool valid() {
return _cost != -1 ? true :
false; }
252 std::stringstream ss;
253 ss <<
"Stance_Path: " <<
static_cast<int>(_off) <<
" ";
254 for(
int i = 0; i < _off; i++)
257 ss <<
"-> " <<
static_cast<int>(
_stances[i]) <<
" " << stance_strings[
_stances[i]];
259 ss <<
" transition: " <<
static_cast<int>(
_stances[i]) <<
" ";
261 fprintf(stderr,
"%s\n", ss.str().c_str());
270 for(
int i = 0; i < _off; i++)
299 BIT_PROPERTY(running)
302 PROPERTY(int8_t, expected_stance)
305 PROPERTY(int8_t, verified_stance)
315 MOTION_Status(
bool running, int8_t expected, int8_t verified)
318 _expected_stance = expected;
319 _verified_stance = verified;
326 bool isRunning() {
return _running; }
340#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
351 void from_string(
const std::string &str)
362 std::string description()
364 std::stringstream ss;
365 ss <<
"Running: " << isRunning() <<
", ";
370 ss << Motions::stance_strings[e];
375 ss <<
"Verified (NYI): ";
378 ss << Motions::stance_strings[v];
420 PROPERTY(int8_t, num_of_stance_actions)
423 BIT_PROPERTY(stance_action_mask)
425 BIT_PROPERTY(ignore_chain)
427 BIT_PROPERTY(ignore_chain_mask)
430 BIT_PROPERTY(head_stiffness)
432 BIT_PROPERTY(body_stiffness)
436 BIT_PROPERTY(head_stiffness_mask)
438 BIT_PROPERTY(body_stiffness_mask)
448 MOTION_Commands(
bool head_stiffness =
false,
bool body_stiffness =
false,
bool masks =
false)
450 memset(
this, 0,
sizeof(*
this));
451 _head_stiffness = head_stiffness;
452 _body_stiffness = body_stiffness;
453 _stance_action_mask =
false;
454 _ignore_chain_mask =
false;
455 _head_stiffness_mask = masks;
456 _body_stiffness_mask = masks;
474 if(current == desired)
483 for (
unsigned i = 0; i < _transitions.size(); i++)
485 if(_transitions[i]._s == current && !p.
contains(_transitions.at(i)._e))
488 p2.
add_stance(_transitions.at(i)._e, _transitions.at(i)._cost,
int(i));
512 fprintf(stderr,
"MOTION_Interface.h: \n"\
514 "\t\tGoToStance change aborted! \n"\
515 "\t\tThe passed variables 'current' and 'desired' must not be equal to Motions::NUM_OF_STANCES. \n"\
516 "\t\tYou may be trying to set them with expected_stance(). This only provides you with a reference to the last Stance that Motion got to. If this is the first Stance change then expected_stance() is set to Motions::NUM_OF_STANCES and you are getting this error.\n");
521 p = decide_stance(current, desired, p);
525 _num_of_stance_actions =
static_cast<int8_t
>(p.
offset());
526 _stance_action_mask =
true;
545 p = decide_stance(current, at.
_s, p);
550 _num_of_stance_actions =
static_cast<int8_t
>(p.
offset()+1);
551 _stance_action_mask =
true;
556#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
569 set_ignore_chain_mask(
false);
572 const char *s = str.c_str();
573 bool want_head_stiffness = isdigit(*s);
575 if (want_head_stiffness)
577 set_head_stiffness_mask();
578 set_head_stiffness(
unsigned(atoi(s)));
579 while (isdigit(*s)) s++;
581 else set_head_stiffness_mask(
false);
582 if (*s ==
',' && isdigit(*++s))
584 set_body_stiffness_mask();
585 set_body_stiffness(
unsigned(atoi(s)));
586 while (isdigit(*s)) s++;
588 else set_body_stiffness_mask(
false);
592 set_stance_action_mask(
false);
597 const char *p = strchr(ss,
',');
598 set_stance_action_mask(p != NULLPTR);
599 std::string str2(ss);
600 str2 = str2.substr(0,
unsigned(p-ss+1));
612 while (*(++s) !=
',') ;
644#pragma clang diagnostic ignored "-Wcovered-switch-default"
645#pragma clang diagnostic ignored "-Wunreachable-code"
653 std::stringstream ss;
654 ss << head_stiffness() <<
"," << body_stiffness();
661#pragma clang diagnostic pop
#define MY_CHECK_ENUM(s, p, v)
#define MAP_ACTION_ENTRY(a, s, c)
#define TRANSITION_NAME(s, e)
#define ACTION_NAME(a, s)
#define JOINT_CHAIN_MAXSIZE
Motion Command class, this class is used to send commands to a motion module via the Whiteboard.
void from_string(const std::string &str)
Parser for recreating this class.
MOTION_Commands(const std::string &str)
String constructor.
long GoToStance(Motions::stance current, Motions::stance desired)
Transition from one 'Stance' to another.
long DoAction(Motions::stance current, Motions::action a)
Perform an 'Action'.
std::string description() const
Description method for pretty printing the values in this class.
Motion Status class, this class reports the status of the Motion engine via the Whiteboard.
Internal class for cost based graph search paths, in this case motion paths.
void add_stance(stance s, int cost)
Add the first stance to this path.
Stance_Path()
Constructor.
bool valid()
is this a valid motion transition
bool contains(stance s)
Check if the current stance path includes the passed in stance.
void invalidate()
set this path in invalid
void pretty_print()
pretty print of the stance path (mainly for debugging)
int offset()
offset getter
int cost()
getter for the path cost (aka time)
u_int8_t _stances[10]
the path taken
void reached()
did this path get to the desired stance
void add_stance(stance s, int cost, int transition)
Add the first stance to this path.
motion_file_layout
This is the file format of the .mot files.
@ NAO_Version
V3 = 0, V4 = 1.
@ Units
RAD = 0 or DEG = 1.
@ Motions
The rest of the file is comma seperated joints and 10ms seperated lines.
@ Joints
Joint numbers, see SensorInfo.h 'jointNames' array.
action
enum values for all actions that can be done
@ Kneeling_signal
When kneeling, signal right arm - Vlad's where to hit.
@ Standing_leftkick
When standing, kick with the left foot.
@ Standing_wave
When standing, wave with one arm.
@ Standing_leftpass
When standing, kick sideways, moving the object in front of the robot left.
@ Standing_rightpass
When standing, kick sideways, moving the object in front of the robot right.
@ Kneeling_raiseright
When kneeling, raise right arm - Vlad's treat to hit.
@ Kneeling_wave
When kneeling, wave with one arm.
@ Kneeling_quickwave
When kneeling, wave quickly with one arm (originally for the RoboCup sound demo)
@ Standing_rightkick
When standing, kick with the right foot.
@ Kneeling_flagwave
When kneeling, wave as if holding a flag - Jeremy's Flag Wave.
@ NUM_OF_ACTIONS
Handy counter for the number of enums.
stance
enum values for all stances
@ Standing_stance
standing up, this is mirrored by the Nao walk engines 'Initialise' pose and means that a motion trans...
@ NUM_OF_STANCES
Handy counter for the number of enums.
@ FallenBack_stance
The robot has fallen backwards. There is no path to the fallen stances, these can only be gotten to b...
@ Standby_stance
Gorilla position, releases stiffness when done (implemented in the Nao motion module)
@ GoalieSaveLeft_stance
Half kneeling and leaning to the left.
@ Kneeling_stance
default kneeling stance - no stiffness by default (implemented in the Nao motion module)
@ GoalieSaveRight_stance
Half kneeling and leaning to the right.
@ FallenForward_stance
The robot has fallen face down. There is no path to the fallen stances, these can only be gotten to b...
Simple struct to store the hardcoded motion 'Actions'.
static const std::map< action, Action_Transition > _actions
This stores all the actions that this API can use and what stance is required to use them.
static std::map< action, Action_Transition > create_actions()
These are the hardcoded Actions that can be used and the Stances required to use them.
Internal struct for representing a motion 'Action' such as Kicking.
int _cost
how long this will take
Action_Transition(action a=Kneeling_wave, stance s=Kneeling_stance, int cost=1)
Constructor.
action _a
the action to be performed, somehow this is 'not really needed here', I can't remember why.
stance _s
the stance required to perform the action
std::string _name
the string name of the action
Internal struct for representing a transition from one from one 'Stance' to another.
Stance_Transition(stance s, stance e, int cost)
Constructor.
std::string _name
the string name of this transition
int _cost
how long this will take
stance _s
the starting stance of this transition
stance _e
the ending stance of this transition
Simple struct to store the hardcoded motion transitions from one 'Stance' to another.
static std::vector< Stance_Transition > create_transitions()
These are the hardcoded transitions from one Stance to another.
static const std::vector< Stance_Transition > _transitions
the storage used for the hardcoded Stance transitions