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