Alex exoskeleton
ALEX SoftwareDocumentation
ExoRobot.cpp
Go to the documentation of this file.
1 #include "ExoRobot.h"
2 
3 #include "DebugMacro.h"
4 
6 }
7 
9  DEBUG_OUT("Delete ExoRobot object begins")
10  freeMemory();
11  joints.clear();
12  copleyDrives.clear();
13  DEBUG_OUT("ExoRobot deleted")
14 }
15 
17  DEBUG_OUT("Initialising Position Control on all joints ")
18  bool returnValue = true;
19  for (auto p : joints) {
21  // Something back happened if were are here
22  DEBUG_OUT("Something bad happened")
23  returnValue = false;
24  }
25  // Put into ReadyToSwitchOn()
26  ((ActuatedJoint *)p)->readyToSwitchOn();
27  }
28 
29  // Pause for a bit to let commands go
30  usleep(2000);
31  for (auto p : joints) {
32  ((ActuatedJoint *)p)->enable();
33  }
34  return returnValue;
35 }
36 
38  DEBUG_OUT("Start New Traj");
39 
40  // Index Resetting
41  currTrajProgress = 0;
42  clock_gettime(CLOCK_MONOTONIC, &prevTime);
43 }
44 
46  bool returnValue = true;
47 
48  timespec currTime;
49  clock_gettime(CLOCK_MONOTONIC, &currTime);
50 
51  double elapsedSec = currTime.tv_sec - prevTime.tv_sec + (currTime.tv_nsec - prevTime.tv_nsec) / 1e9;
52  prevTime = currTime;
53 
54  // This should check to make sure that the "GO" button is pressed.
55  if (true) {
56  currTrajProgress += elapsedSec;
57  DEBUG_OUT("Elapsed Time: " << currTrajProgress)
58 
59  std::vector<double> setPoints = trajectoryGenerator->getSetPoint(currTrajProgress);
60  int i = 0;
61  for (auto p : joints) {
62  setMovementReturnCode_t setPosCode = ((ActuatedJoint *)p)->setPosition(setPoints[i]);
63  if (setPosCode == INCORRECT_MODE) {
64  std::cout << "Joint ID " << p->getId() << ": is not in Position Control " << std::endl;
65  returnValue = false;
66  } else if (setPosCode != SUCCESS) {
67  // Something bad happened
68  std::cout << "Joint " << p->getId() << ": Unknown Error " << std::endl;
69  returnValue = false;
70  }
71  i++;
72  }
73  } else {
74  DEBUG_OUT("Not moving")
75  }
76 
77  return returnValue;
78 }
79 
81  for (int id = 0; id < NUM_JOINTS; id++) {
82  copleyDrives.push_back(new CopleyDrive(id + 1));
83  joints.push_back(new DummyActJoint(id, jointMinMap[id], jointMaxMap[id], copleyDrives[id]));
84  }
85  return true;
86 }
87 
89  DEBUG_OUT("ExoRobot::initialiseNetwork()");
90 
91  bool status;
92  for (auto joint : joints) {
93  status = joint->initNetwork();
94  if (!status)
95  return false;
96  }
97 
98  return true;
99 }
101  inputs.push_back(new Keyboard());
102  return true;
103 }
106  for (auto p : joints) {
107  DEBUG_OUT("Delete Joint ID: " << p->getId())
108  delete p;
109  }
110  for (auto p : copleyDrives) {
111  DEBUG_OUT("Delete Drive Node: " << p->getNodeID())
112  delete p;
113  }
114 }
118 }
void freeMemory()
Free robot objects vector pointer memory.
Definition: ExoRobot.cpp:104
bool initPositionControl()
Initialises all joints to position control mode.
Definition: ExoRobot.cpp:16
TrajectoryGenerator * trajectoryGenerator
Trajectory Generator.
Definition: Robot.h:44
vector< CopleyDrive * > copleyDrives
Definition: ExoRobot.h:49
virtual std::vector< double > getSetPoint(double time)=0
Get the next step point in the trajectory.
void updateInput()
defintion of <class>Input</class> pure virtual function. Updates the keyboard input devices memory st...
Definition: Keyboard.cpp:22
Abstract Class representing a robot. Includes vectors of Joint and InputDevice.
Definition: Robot.h:28
~Keyboard()
Definition: Keyboard.cpp:17
bool initialiseNetwork()
Implementation of Pure Virtual function from Robot Base class. Initialize each Drive Objects underlyi...
Definition: ExoRobot.cpp:88
timespec prevTime
Definition: ExoRobot.h:33
Example implementation of the ActuatedJoints class.
Definition: DummyActJoint.h:22
double currTrajProgress
Definition: ExoRobot.h:32
Example InputDevice which takes input in from a keyboard. Useful for testing without any other input ...
Definition: Keyboard.h:36
bool initialiseJoints()
Implementation of Pure Virtual function from Robot Base class. Create designed Joint and Driver objec...
Definition: ExoRobot.cpp:80
vector< Joint * > joints
Vector of pointers to Abstract <class>Joint<class> Objects, number and type must be specified by Soft...
Definition: Robot.h:37
#define NUM_JOINTS
Definition: RobotParams.h:13
bool moveThroughTraj()
For each joint, move through(send appropriate commands to joints) the Currently generated trajectory ...
Definition: ExoRobot.cpp:45
setMovementReturnCode_t
Definition: ActuatedJoint.h:21
Abstract class representing an actuated joint in a Robot Class (extending joint). Requires a Drive ob...
Definition: ActuatedJoint.h:32
motorProfile posControlMotorProfile
motor drive position control profile paramaters
Definition: ExoRobot.h:38
~ExoRobot()
Definition: ExoRobot.cpp:8
An implementation of the Drive Object, specifically for Copley-branded devices (currently used on the...
Definition: CopleyDrive.h:16
ExoRobot(TrajectoryGenerator *tj)
Default ExoRobot constructor. Initialize memory for the Exoskelton Joint + sensors. Load in exoskeleton paramaters to TrajectoryGenerator..
Definition: ExoRobot.cpp:5
Abstract class which is used to generate trajectorys for a Robot to follow.
vector< InputDevice * > inputs
Definition: Robot.h:39
void startNewTraj()
Begin a new trajectory with the currently loaded trajectory paramaters. Using the ExoRobot current co...
Definition: ExoRobot.cpp:37
#define DEBUG_OUT(x)
Definition: DebugMacro.h:11
virtual void updateRobot()
Update all of this Robot software joint positions from object dictionary entries. ...
Definition: Robot.cpp:37
std::map< int, double > jointMaxMap
Joint Limit Map between Joint value and max Degrees possible.
Definition: ExoRobot.h:134
Keyboard keyboard
Definition: ExoRobot.h:48
void updateRobot()
update current state of the robot, including input and output devices. Overloaded Method from the Rob...
Definition: ExoRobot.cpp:115
bool initialiseInputs()
Implementation of Pure Virtual function from Robot Base class. Initialize each Input Object...
Definition: ExoRobot.cpp:100
std::map< int, double > jointMinMap
Joint Limit Map between Joint value and min Degrees possible.
Definition: ExoRobot.h:123