For YRL Robot Arm

Dependents:   PR_RobotArm_Show_Positions

Fork of PR-RobotArmController by James Hilder

Committer:
jah128
Date:
Fri Mar 03 13:37:44 2017 +0000
Revision:
1:aa92ba95a4bb
Parent:
0:b14dfd8816da
fixed wrist bug;

Who changed what in which revision?

UserRevisionLine numberNew 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 1:aa92ba95a4bb 51 #define WRIST_LIMIT_LOW 300
jah128 1:aa92ba95a4bb 52 #define WRIST_LIMIT_HIGH 700
jah128 0:b14dfd8816da 53 #define USE_LIMIT_WARNING 1
jah128 0:b14dfd8816da 54
jah128 0:b14dfd8816da 55 #define BASE 10
jah128 0:b14dfd8816da 56 #define SHOULDER 11
jah128 0:b14dfd8816da 57 #define ELBOW 12
jah128 0:b14dfd8816da 58 #define WRIST 13
jah128 0:b14dfd8816da 59
jah128 0:b14dfd8816da 60 #include "mbed.h"
jah128 0:b14dfd8816da 61 #include "display.h"
jah128 0:b14dfd8816da 62 #include "remote.h"
jah128 0:b14dfd8816da 63 #include "servo.h"
jah128 0:b14dfd8816da 64 #include "SerialHalfDuplex.h"
jah128 0:b14dfd8816da 65
jah128 0:b14dfd8816da 66 extern Display display;
jah128 0:b14dfd8816da 67 extern Remote remote;
jah128 0:b14dfd8816da 68 extern Serial pc;
jah128 0:b14dfd8816da 69 extern Serial servo_data;
jah128 0:b14dfd8816da 70 extern Servo servo;
jah128 0:b14dfd8816da 71
jah128 0:b14dfd8816da 72 extern char remote_on;
jah128 0:b14dfd8816da 73 extern short target_base;
jah128 0:b14dfd8816da 74 extern short target_shoulder;
jah128 0:b14dfd8816da 75 extern short target_elbow;
jah128 0:b14dfd8816da 76 extern short target_wrist;
jah128 0:b14dfd8816da 77
jah128 0:b14dfd8816da 78 /** Robotarm Class
jah128 0:b14dfd8816da 79 * The main class to define the robot arm
jah128 0:b14dfd8816da 80 *
jah128 0:b14dfd8816da 81 * Example code for main.cpp:
jah128 0:b14dfd8816da 82 * @code
jah128 0:b14dfd8816da 83 * #include "robotarm.h"
jah128 0:b14dfd8816da 84 * Robotarm arm;
jah128 0:b14dfd8816da 85 * int main(){
jah128 0:b14dfd8816da 86 * arm.init();
jah128 0:b14dfd8816da 87 * while(1) { //Do something!
jah128 0:b14dfd8816da 88 * }
jah128 0:b14dfd8816da 89 * }
jah128 0:b14dfd8816da 90 * @endcode
jah128 0:b14dfd8816da 91 */
jah128 0:b14dfd8816da 92 class Robotarm
jah128 0:b14dfd8816da 93 {
jah128 0:b14dfd8816da 94 public:
jah128 0:b14dfd8816da 95 /**
jah128 0:b14dfd8816da 96 * Main initialisation routine for the robot arm
jah128 0:b14dfd8816da 97 *
jah128 0:b14dfd8816da 98 * Set up the display, set up listener for remote control, set up servos
jah128 0:b14dfd8816da 99 */
jah128 0:b14dfd8816da 100 void init(void);
jah128 0:b14dfd8816da 101
jah128 0:b14dfd8816da 102 /**
jah128 0:b14dfd8816da 103 * Test and initialise the servo motors
jah128 0:b14dfd8816da 104 */
jah128 0:b14dfd8816da 105 void init_servos(void);
jah128 0:b14dfd8816da 106
jah128 0:b14dfd8816da 107 /**
jah128 0:b14dfd8816da 108 * Zero the servo motors (set to center position and activate)
jah128 0:b14dfd8816da 109 * @param time_delay: The time delay in seconds to wait before zeroing (0=no delay)
jah128 0:b14dfd8816da 110 */
jah128 0:b14dfd8816da 111 void zero_servos(float time_delay);
jah128 0:b14dfd8816da 112
jah128 0:b14dfd8816da 113 /**
jah128 0:b14dfd8816da 114 * Called when servo initialisation fails; displays warning and halts program.
jah128 0:b14dfd8816da 115 */
jah128 0:b14dfd8816da 116 void fail_init(void);
jah128 0:b14dfd8816da 117
jah128 0:b14dfd8816da 118 /**
jah128 0:b14dfd8816da 119 * Hardware test scans for all servos at different baud rates
jah128 0:b14dfd8816da 120 */
jah128 0:b14dfd8816da 121 void hardware_test(void);
jah128 0:b14dfd8816da 122
jah128 0:b14dfd8816da 123 /**
jah128 0:b14dfd8816da 124 * Initialise_servo is used to set the EPROM on a single servo so that its
jah128 0:b14dfd8816da 125 * ID and baud rate are correct; only to be used in initial configuration of the
jah128 0:b14dfd8816da 126 * arm, not in a normal program
jah128 0:b14dfd8816da 127 */
jah128 0:b14dfd8816da 128 void initialise_servo(int target_servo);
jah128 0:b14dfd8816da 129
jah128 0:b14dfd8816da 130 private:
jah128 0:b14dfd8816da 131
jah128 0:b14dfd8816da 132 void _zero_servos(void);
jah128 0:b14dfd8816da 133 void _zero_servos_display_update(void);
jah128 0:b14dfd8816da 134 };
jah128 0:b14dfd8816da 135 #endif // ROBOTARM_H
jah128 0:b14dfd8816da 136
jah128 0:b14dfd8816da 137 /*
jah128 0:b14dfd8816da 138 * Copyright 2017 University of York
jah128 0:b14dfd8816da 139 *
jah128 0:b14dfd8816da 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:b14dfd8816da 141 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
jah128 0:b14dfd8816da 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:b14dfd8816da 143 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
jah128 0:b14dfd8816da 144 * See the License for the specific language governing permissions and limitations under the License.
jah128 0:b14dfd8816da 145 *
jah128 0:b14dfd8816da 146 */