demo project
Dependencies: AX-12A Dynamixel mbed iothub_client EthernetInterface NTPClient ConfigFile SDFileSystem iothub_amqp_transport mbed-rtos proton-c-mbed wolfSSL
RobotArm.h@33:8b9dcbf6d8ec, 2016-02-04 (annotated)
- Committer:
- henryrawas
- Date:
- Thu Feb 04 20:10:33 2016 +0000
- Revision:
- 33:8b9dcbf6d8ec
- Parent:
- 19:2f0ec9ac1238
update libs
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
henryrawas | 19:2f0ec9ac1238 | 1 | // Copyright (c) Microsoft. All rights reserved. |
henryrawas | 19:2f0ec9ac1238 | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
henryrawas | 4:36a4eceb1b7f | 3 | |
henryrawas | 4:36a4eceb1b7f | 4 | #ifndef __ROBOT_ARM_H__ |
henryrawas | 4:36a4eceb1b7f | 5 | #define __ROBOT_ARM_H__ |
henryrawas | 4:36a4eceb1b7f | 6 | |
henryrawas | 4:36a4eceb1b7f | 7 | #include "mbed.h" |
henryrawas | 4:36a4eceb1b7f | 8 | #include "rtos.h" |
henryrawas | 4:36a4eceb1b7f | 9 | |
henryrawas | 4:36a4eceb1b7f | 10 | #include "DynamixelBus.h" |
henryrawas | 12:ac6c9d7f8c40 | 11 | #include "NodeAX12.h" |
henryrawas | 18:224289104fc0 | 12 | #include "RobotArmCfg.h" |
henryrawas | 4:36a4eceb1b7f | 13 | |
henryrawas | 7:6723f6887d00 | 14 | |
henryrawas | 4:36a4eceb1b7f | 15 | class RobotArm |
henryrawas | 4:36a4eceb1b7f | 16 | { |
henryrawas | 4:36a4eceb1b7f | 17 | public: |
henryrawas | 4:36a4eceb1b7f | 18 | |
henryrawas | 4:36a4eceb1b7f | 19 | RobotArm(); |
henryrawas | 4:36a4eceb1b7f | 20 | |
henryrawas | 13:ffeff9b5e513 | 21 | // move all parts to specified postions in ms time - start |
henryrawas | 13:ffeff9b5e513 | 22 | bool MoveArmPositionsStart(float positions[], int ms); |
henryrawas | 13:ffeff9b5e513 | 23 | |
henryrawas | 13:ffeff9b5e513 | 24 | // move all parts to specified postions - resume after pause |
henryrawas | 13:ffeff9b5e513 | 25 | bool MoveArmPositionsResume(); |
henryrawas | 4:36a4eceb1b7f | 26 | |
henryrawas | 13:ffeff9b5e513 | 27 | // move all parts to specified postions - test if done |
henryrawas | 4:36a4eceb1b7f | 28 | bool MoveArmPositionsHasNext(); |
henryrawas | 4:36a4eceb1b7f | 29 | |
henryrawas | 13:ffeff9b5e513 | 30 | // move all parts to specified postions - next step |
henryrawas | 7:6723f6887d00 | 31 | bool MoveArmPositionsNext(); |
henryrawas | 7:6723f6887d00 | 32 | |
henryrawas | 13:ffeff9b5e513 | 33 | // move all parts to specified postions - next step delay |
henryrawas | 7:6723f6887d00 | 34 | bool MoveArmPositionsDelay(int& nextdelay); |
henryrawas | 4:36a4eceb1b7f | 35 | |
henryrawas | 13:ffeff9b5e513 | 36 | // move all parts to specified postions - finish |
henryrawas | 4:36a4eceb1b7f | 37 | bool MoveArmPositionsEnd(); |
henryrawas | 5:36916b1c5a06 | 38 | |
henryrawas | 13:ffeff9b5e513 | 39 | // reset goal to the current position ie. stop trying to move |
henryrawas | 13:ffeff9b5e513 | 40 | void MoveArmPositionsStop(); |
henryrawas | 4:36a4eceb1b7f | 41 | |
henryrawas | 11:3a2e6eb9fbb8 | 42 | // clear part error state |
henryrawas | 11:3a2e6eb9fbb8 | 43 | void ClearErrorState(); |
henryrawas | 11:3a2e6eb9fbb8 | 44 | |
henryrawas | 4:36a4eceb1b7f | 45 | // get all parts positions |
henryrawas | 13:ffeff9b5e513 | 46 | bool GetArmPositions(float outVals[]); |
henryrawas | 4:36a4eceb1b7f | 47 | |
henryrawas | 4:36a4eceb1b7f | 48 | // get all parts last positions |
henryrawas | 13:ffeff9b5e513 | 49 | bool GetArmLastPositions(float outVals[]); |
henryrawas | 13:ffeff9b5e513 | 50 | |
henryrawas | 15:4bd10f531cdc | 51 | // prepare to test arm state |
henryrawas | 15:4bd10f531cdc | 52 | void ArmMeasuresTestStart(); |
henryrawas | 15:4bd10f531cdc | 53 | |
henryrawas | 13:ffeff9b5e513 | 54 | // test if measurements are in expected range |
henryrawas | 13:ffeff9b5e513 | 55 | int ArmMeasuresTest(int measureId); |
henryrawas | 4:36a4eceb1b7f | 56 | |
henryrawas | 4:36a4eceb1b7f | 57 | // get all parts for a measurement |
henryrawas | 13:ffeff9b5e513 | 58 | bool GetArmMeasure(int measureId, float outVals[]); |
henryrawas | 4:36a4eceb1b7f | 59 | |
henryrawas | 4:36a4eceb1b7f | 60 | // get all parts last measurement |
henryrawas | 13:ffeff9b5e513 | 61 | bool GetArmLastMeasure(int measureId, float outVals[]); |
henryrawas | 4:36a4eceb1b7f | 62 | |
henryrawas | 4:36a4eceb1b7f | 63 | int GetNumParts(); |
henryrawas | 4:36a4eceb1b7f | 64 | |
henryrawas | 4:36a4eceb1b7f | 65 | // set arm speed as ms between steps |
henryrawas | 4:36a4eceb1b7f | 66 | void SetStepMs(int stepms); |
henryrawas | 4:36a4eceb1b7f | 67 | |
henryrawas | 4:36a4eceb1b7f | 68 | // set ThreadId for signals |
henryrawas | 4:36a4eceb1b7f | 69 | void SetThreadId(osThreadId tid); |
henryrawas | 4:36a4eceb1b7f | 70 | |
henryrawas | 4:36a4eceb1b7f | 71 | // get the part object |
henryrawas | 4:36a4eceb1b7f | 72 | RobotNode* GetArmPart(int partIx); |
henryrawas | 4:36a4eceb1b7f | 73 | |
henryrawas | 4:36a4eceb1b7f | 74 | // get last error code from action |
henryrawas | 7:6723f6887d00 | 75 | int GetLastError(); |
henryrawas | 4:36a4eceb1b7f | 76 | |
henryrawas | 4:36a4eceb1b7f | 77 | // get index of part with error |
henryrawas | 4:36a4eceb1b7f | 78 | int GetLastErrorPart(); |
henryrawas | 4:36a4eceb1b7f | 79 | |
henryrawas | 7:6723f6887d00 | 80 | // get size of position diff (valid if error) |
henryrawas | 7:6723f6887d00 | 81 | float GetLastPosDiff(); |
henryrawas | 7:6723f6887d00 | 82 | |
henryrawas | 4:36a4eceb1b7f | 83 | private: |
henryrawas | 4:36a4eceb1b7f | 84 | // sensors and actuators |
henryrawas | 13:ffeff9b5e513 | 85 | RobotNode* _armParts[NUMJOINTS]; |
henryrawas | 4:36a4eceb1b7f | 86 | |
henryrawas | 4:36a4eceb1b7f | 87 | int _numParts; |
henryrawas | 4:36a4eceb1b7f | 88 | |
henryrawas | 4:36a4eceb1b7f | 89 | // #ms between steps |
henryrawas | 4:36a4eceb1b7f | 90 | int _stepms; |
henryrawas | 4:36a4eceb1b7f | 91 | |
henryrawas | 4:36a4eceb1b7f | 92 | // thread id |
henryrawas | 4:36a4eceb1b7f | 93 | osThreadId _tid; |
henryrawas | 4:36a4eceb1b7f | 94 | |
henryrawas | 4:36a4eceb1b7f | 95 | // part ix for last error |
henryrawas | 4:36a4eceb1b7f | 96 | int _lastErrorPart; |
henryrawas | 7:6723f6887d00 | 97 | // last HW error |
henryrawas | 7:6723f6887d00 | 98 | int _lastError; |
henryrawas | 7:6723f6887d00 | 99 | // last position error |
henryrawas | 7:6723f6887d00 | 100 | float _lastPosDiff; |
henryrawas | 4:36a4eceb1b7f | 101 | |
henryrawas | 8:d98e2dec0f40 | 102 | // step-wise position moves |
henryrawas | 18:224289104fc0 | 103 | float _endgoals[NUMJOINTS]; |
henryrawas | 18:224289104fc0 | 104 | float _differentials[NUMJOINTS]; |
henryrawas | 18:224289104fc0 | 105 | float _lastpos[NUMJOINTS]; |
henryrawas | 18:224289104fc0 | 106 | float _lastgoals[NUMJOINTS]; |
henryrawas | 5:36916b1c5a06 | 107 | |
henryrawas | 7:6723f6887d00 | 108 | // keep track of time period when position is off |
henryrawas | 18:224289104fc0 | 109 | int _failms[NUMJOINTS]; |
henryrawas | 5:36916b1c5a06 | 110 | |
henryrawas | 18:224289104fc0 | 111 | int _numsteps; |
henryrawas | 18:224289104fc0 | 112 | int _curstep; |
henryrawas | 18:224289104fc0 | 113 | int _delayms; |
henryrawas | 18:224289104fc0 | 114 | int _expDelay; |
henryrawas | 18:224289104fc0 | 115 | Timer _elapseTimer; |
henryrawas | 4:36a4eceb1b7f | 116 | }; |
henryrawas | 4:36a4eceb1b7f | 117 | |
henryrawas | 4:36a4eceb1b7f | 118 | #endif |