Robot Arm Controller Library
Dependents: PR_RobotArm lighthouse_2
robotarm.h@0:9f7b70e0186e, 2017-02-16 (annotated)
- Committer:
- jah128
- Date:
- Thu Feb 16 23:57:45 2017 +0000
- Revision:
- 0:9f7b70e0186e
First commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 0:9f7b70e0186e | 1 | /* University of York Robotics Laboratory Robot Arm Controller Board |
jah128 | 0:9f7b70e0186e | 2 | * |
jah128 | 0:9f7b70e0186e | 3 | * Robot Arm Controller |
jah128 | 0:9f7b70e0186e | 4 | * |
jah128 | 0:9f7b70e0186e | 5 | * File: robotarm.h |
jah128 | 0:9f7b70e0186e | 6 | * |
jah128 | 0:9f7b70e0186e | 7 | * (C) Dept. Electronics & Computer Science, University of York |
jah128 | 0:9f7b70e0186e | 8 | * |
jah128 | 0:9f7b70e0186e | 9 | * James Hilder, Alan Millard, Shuhei Miyashita, Homero Elizondo, Jon Timmis |
jah128 | 0:9f7b70e0186e | 10 | * |
jah128 | 0:9f7b70e0186e | 11 | * February 2017, Version 1.0 |
jah128 | 0:9f7b70e0186e | 12 | */ |
jah128 | 0:9f7b70e0186e | 13 | |
jah128 | 0:9f7b70e0186e | 14 | |
jah128 | 0:9f7b70e0186e | 15 | #ifndef ROBOTARM_H |
jah128 | 0:9f7b70e0186e | 16 | #define ROBOTARM_H |
jah128 | 0:9f7b70e0186e | 17 | |
jah128 | 0:9f7b70e0186e | 18 | #define SOFTWARE_VERSION_CODE 1.0 |
jah128 | 0:9f7b70e0186e | 19 | #define LCD_ADDRESS 0x7C |
jah128 | 0:9f7b70e0186e | 20 | |
jah128 | 0:9f7b70e0186e | 21 | // Remote control definitions: |
jah128 | 0:9f7b70e0186e | 22 | // REMOTE_ENABLED = 1 to enable remote control polling |
jah128 | 0:9f7b70e0186e | 23 | // REMOTE_POLL_RATE = poll rate in microseconds |
jah128 | 0:9f7b70e0186e | 24 | // REMOTE_LINEAR_STEPS = 1 to use same step amount each step; 0 to use a exponentially increasing amount as button held |
jah128 | 0:9f7b70e0186e | 25 | // REMOTE_START_SPEED = Size of step to use; suggest 2 for LINEAR_STEPS=0 or 10 for LINEAR_STEPS=1 |
jah128 | 0:9f7b70e0186e | 26 | // REMOTE_USE_CURRENT_POSITION = 0 will move based on the stored target position, 1 will read the current position and set target accordingly. This may make certain settings combinations fail to move under cases of high-torque load and low step size |
jah128 | 0:9f7b70e0186e | 27 | #define REMOTE_ENABLED 1 |
jah128 | 0:9f7b70e0186e | 28 | #define REMOTE_POLL_RATE 15627 |
jah128 | 0:9f7b70e0186e | 29 | #define REMOTE_LINEAR_STEPS 1 |
jah128 | 0:9f7b70e0186e | 30 | #define REMOTE_START_SPEED 10 |
jah128 | 0:9f7b70e0186e | 31 | #define REMOTE_USE_CURRENT_POSITION 0 |
jah128 | 0:9f7b70e0186e | 32 | |
jah128 | 0:9f7b70e0186e | 33 | #define HAS_BASE 1 |
jah128 | 0:9f7b70e0186e | 34 | #define HAS_SHOULDER 1 |
jah128 | 0:9f7b70e0186e | 35 | #define HAS_ELBOW 1 |
jah128 | 0:9f7b70e0186e | 36 | #define HAS_WRIST 1 |
jah128 | 0:9f7b70e0186e | 37 | |
jah128 | 0:9f7b70e0186e | 38 | #define INVERT_BASE 1 |
jah128 | 0:9f7b70e0186e | 39 | #define INVERT_SHOULDER 1 |
jah128 | 0:9f7b70e0186e | 40 | #define INVERT_ELBOW 0 |
jah128 | 0:9f7b70e0186e | 41 | #define INVERT_WRIST 0 |
jah128 | 0:9f7b70e0186e | 42 | |
jah128 | 0:9f7b70e0186e | 43 | // Define the zero (middle\default) positions for the servos |
jah128 | 0:9f7b70e0186e | 44 | #define BASE_ZERO 2048 |
jah128 | 0:9f7b70e0186e | 45 | #define SHOULDER_ZERO 2048 |
jah128 | 0:9f7b70e0186e | 46 | #define ELBOW_ZERO 2048 |
jah128 | 0:9f7b70e0186e | 47 | #define WRIST_ZERO 512 |
jah128 | 0:9f7b70e0186e | 48 | |
jah128 | 0:9f7b70e0186e | 49 | // If USE_SOFT_LIMITS = 1, SERVOS WILL BE LIMITED TO RANGES THAT FOLLOW |
jah128 | 0:9f7b70e0186e | 50 | // We can also program the servos so they do not go outside limits..... |
jah128 | 0:9f7b70e0186e | 51 | #define USE_SOFT_LIMITS 1 |
jah128 | 0:9f7b70e0186e | 52 | #define BASE_LIMIT_LOW 100 |
jah128 | 0:9f7b70e0186e | 53 | #define BASE_LIMIT_HIGH 4000 |
jah128 | 0:9f7b70e0186e | 54 | #define SHOULDER_LIMIT_LOW 700 |
jah128 | 0:9f7b70e0186e | 55 | #define SHOULDER_LIMIT_HIGH 3400 |
jah128 | 0:9f7b70e0186e | 56 | #define ELBOW_LIMIT_LOW 380 |
jah128 | 0:9f7b70e0186e | 57 | #define ELBOW_LIMIT_HIGH 3720 |
jah128 | 0:9f7b70e0186e | 58 | #define WRIST_LIMIT_LOW 0 |
jah128 | 0:9f7b70e0186e | 59 | #define WRIST_LIMIT_HIGH 1023 |
jah128 | 0:9f7b70e0186e | 60 | #define USE_LIMIT_WARNING 1 |
jah128 | 0:9f7b70e0186e | 61 | |
jah128 | 0:9f7b70e0186e | 62 | #define BASE 10 |
jah128 | 0:9f7b70e0186e | 63 | #define SHOULDER 11 |
jah128 | 0:9f7b70e0186e | 64 | #define ELBOW 12 |
jah128 | 0:9f7b70e0186e | 65 | #define WRIST 13 |
jah128 | 0:9f7b70e0186e | 66 | |
jah128 | 0:9f7b70e0186e | 67 | #include "mbed.h" |
jah128 | 0:9f7b70e0186e | 68 | #include "display.h" |
jah128 | 0:9f7b70e0186e | 69 | #include "remote.h" |
jah128 | 0:9f7b70e0186e | 70 | #include "servo.h" |
jah128 | 0:9f7b70e0186e | 71 | #include "SerialHalfDuplex.h" |
jah128 | 0:9f7b70e0186e | 72 | |
jah128 | 0:9f7b70e0186e | 73 | extern Display display; |
jah128 | 0:9f7b70e0186e | 74 | extern Remote remote; |
jah128 | 0:9f7b70e0186e | 75 | extern Serial pc; |
jah128 | 0:9f7b70e0186e | 76 | extern Serial servo_data; |
jah128 | 0:9f7b70e0186e | 77 | extern Servo servo; |
jah128 | 0:9f7b70e0186e | 78 | |
jah128 | 0:9f7b70e0186e | 79 | extern char remote_on; |
jah128 | 0:9f7b70e0186e | 80 | extern short target_base; |
jah128 | 0:9f7b70e0186e | 81 | extern short target_shoulder; |
jah128 | 0:9f7b70e0186e | 82 | extern short target_elbow; |
jah128 | 0:9f7b70e0186e | 83 | extern short target_wrist; |
jah128 | 0:9f7b70e0186e | 84 | |
jah128 | 0:9f7b70e0186e | 85 | /** Robotarm Class |
jah128 | 0:9f7b70e0186e | 86 | * The main class to define the robot arm |
jah128 | 0:9f7b70e0186e | 87 | * |
jah128 | 0:9f7b70e0186e | 88 | * Example code for main.cpp: |
jah128 | 0:9f7b70e0186e | 89 | * @code |
jah128 | 0:9f7b70e0186e | 90 | * #include "robotarm.h" |
jah128 | 0:9f7b70e0186e | 91 | * Robotarm arm; |
jah128 | 0:9f7b70e0186e | 92 | * int main(){ |
jah128 | 0:9f7b70e0186e | 93 | * arm.init(); |
jah128 | 0:9f7b70e0186e | 94 | * while(1) { //Do something! |
jah128 | 0:9f7b70e0186e | 95 | * } |
jah128 | 0:9f7b70e0186e | 96 | * } |
jah128 | 0:9f7b70e0186e | 97 | * @endcode |
jah128 | 0:9f7b70e0186e | 98 | */ |
jah128 | 0:9f7b70e0186e | 99 | class Robotarm |
jah128 | 0:9f7b70e0186e | 100 | { |
jah128 | 0:9f7b70e0186e | 101 | public: |
jah128 | 0:9f7b70e0186e | 102 | /** |
jah128 | 0:9f7b70e0186e | 103 | * Main initialisation routine for the robot arm |
jah128 | 0:9f7b70e0186e | 104 | * |
jah128 | 0:9f7b70e0186e | 105 | * Set up the display, set up listener for remote control, set up servos |
jah128 | 0:9f7b70e0186e | 106 | */ |
jah128 | 0:9f7b70e0186e | 107 | void init(void); |
jah128 | 0:9f7b70e0186e | 108 | |
jah128 | 0:9f7b70e0186e | 109 | /** |
jah128 | 0:9f7b70e0186e | 110 | * Test and initialise the servo motors |
jah128 | 0:9f7b70e0186e | 111 | */ |
jah128 | 0:9f7b70e0186e | 112 | void init_servos(void); |
jah128 | 0:9f7b70e0186e | 113 | |
jah128 | 0:9f7b70e0186e | 114 | /** |
jah128 | 0:9f7b70e0186e | 115 | * Zero the servo motors (set to center position and activate) |
jah128 | 0:9f7b70e0186e | 116 | * @param time_delay: The time delay in seconds to wait before zeroing (0=no delay) |
jah128 | 0:9f7b70e0186e | 117 | */ |
jah128 | 0:9f7b70e0186e | 118 | void zero_servos(float time_delay); |
jah128 | 0:9f7b70e0186e | 119 | |
jah128 | 0:9f7b70e0186e | 120 | /** |
jah128 | 0:9f7b70e0186e | 121 | * Called when servo initialisation fails; displays warning and halts program. |
jah128 | 0:9f7b70e0186e | 122 | */ |
jah128 | 0:9f7b70e0186e | 123 | void fail_init(void); |
jah128 | 0:9f7b70e0186e | 124 | |
jah128 | 0:9f7b70e0186e | 125 | /** |
jah128 | 0:9f7b70e0186e | 126 | * Hardware test scans for all servos at different baud rates |
jah128 | 0:9f7b70e0186e | 127 | */ |
jah128 | 0:9f7b70e0186e | 128 | void hardware_test(void); |
jah128 | 0:9f7b70e0186e | 129 | |
jah128 | 0:9f7b70e0186e | 130 | private: |
jah128 | 0:9f7b70e0186e | 131 | |
jah128 | 0:9f7b70e0186e | 132 | void _zero_servos(void); |
jah128 | 0:9f7b70e0186e | 133 | void _zero_servos_display_update(void); |
jah128 | 0:9f7b70e0186e | 134 | }; |
jah128 | 0:9f7b70e0186e | 135 | #endif // ROBOTARM_H |
jah128 | 0:9f7b70e0186e | 136 | |
jah128 | 0:9f7b70e0186e | 137 | /* |
jah128 | 0:9f7b70e0186e | 138 | * Copyright 2017 University of York |
jah128 | 0:9f7b70e0186e | 139 | * |
jah128 | 0:9f7b70e0186e | 140 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. |
jah128 | 0:9f7b70e0186e | 141 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
jah128 | 0:9f7b70e0186e | 142 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS |
jah128 | 0:9f7b70e0186e | 143 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
jah128 | 0:9f7b70e0186e | 144 | * See the License for the specific language governing permissions and limitations under the License. |
jah128 | 0:9f7b70e0186e | 145 | * |
jah128 | 0:9f7b70e0186e | 146 | */ |