Refactoring Ironcup 2020
Dependencies: mbed mbed-rtos MotionSensor EthernetInterface
Protocol/Protocol/protocol.h@0:8f5db5085df7, 2020-09-21 (annotated)
- Committer:
- starling
- Date:
- Mon Sep 21 21:42:07 2020 +0000
- Revision:
- 0:8f5db5085df7
12 mar 2020
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
starling | 0:8f5db5085df7 | 1 | /** |
starling | 0:8f5db5085df7 | 2 | @file protocol.h |
starling | 0:8f5db5085df7 | 3 | @brief Protocol definitions. |
starling | 0:8f5db5085df7 | 4 | */ |
starling | 0:8f5db5085df7 | 5 | |
starling | 0:8f5db5085df7 | 6 | /* |
starling | 0:8f5db5085df7 | 7 | Copyright 2016 Erik Perillo <erik.perillo@gmail.com> |
starling | 0:8f5db5085df7 | 8 | |
starling | 0:8f5db5085df7 | 9 | This file is part of piranha-ptc. |
starling | 0:8f5db5085df7 | 10 | |
starling | 0:8f5db5085df7 | 11 | This is free software: you can redistribute it and/or modify |
starling | 0:8f5db5085df7 | 12 | it under the terms of the GNU General Public License as published by |
starling | 0:8f5db5085df7 | 13 | the Free Software Foundation, either version 3 of the License, or |
starling | 0:8f5db5085df7 | 14 | (at your option) any later version. |
starling | 0:8f5db5085df7 | 15 | |
starling | 0:8f5db5085df7 | 16 | This is distributed in the hope that it will be useful, |
starling | 0:8f5db5085df7 | 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
starling | 0:8f5db5085df7 | 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
starling | 0:8f5db5085df7 | 19 | See the GNU General Public License for more details. |
starling | 0:8f5db5085df7 | 20 | |
starling | 0:8f5db5085df7 | 21 | You should have received a copy of the GNU General Public License |
starling | 0:8f5db5085df7 | 22 | along with this. If not, see <http://www.gnu.org/licenses/>. |
starling | 0:8f5db5085df7 | 23 | */ |
starling | 0:8f5db5085df7 | 24 | |
starling | 0:8f5db5085df7 | 25 | |
starling | 0:8f5db5085df7 | 26 | #ifndef __PIRANHA_PROTOCOL_H__ |
starling | 0:8f5db5085df7 | 27 | #define __PIRANHA_PROTOCOL_H__ |
starling | 0:8f5db5085df7 | 28 | |
starling | 0:8f5db5085df7 | 29 | //@{ |
starling | 0:8f5db5085df7 | 30 | ///PID parameters range. |
starling | 0:8f5db5085df7 | 31 | #define PID_PARAMS_MIN 0.0 |
starling | 0:8f5db5085df7 | 32 | #define PID_PARAMS_MAX 100.0 |
starling | 0:8f5db5085df7 | 33 | //@} |
starling | 0:8f5db5085df7 | 34 | |
starling | 0:8f5db5085df7 | 35 | //@{ |
starling | 0:8f5db5085df7 | 36 | ///Ground velocity range. |
starling | 0:8f5db5085df7 | 37 | #define GND_VEL_MIN -100.0 |
starling | 0:8f5db5085df7 | 38 | #define GND_VEL_MAX 100.0 |
starling | 0:8f5db5085df7 | 39 | //@} |
starling | 0:8f5db5085df7 | 40 | |
starling | 0:8f5db5085df7 | 41 | //@{ |
starling | 0:8f5db5085df7 | 42 | ///Angle reference range (in radians). |
starling | 0:8f5db5085df7 | 43 | #define PI 3.141593 |
starling | 0:8f5db5085df7 | 44 | #define ABS_ANG_REF_MIN -PI |
starling | 0:8f5db5085df7 | 45 | #define ABS_ANG_REF_MAX PI |
starling | 0:8f5db5085df7 | 46 | //@} |
starling | 0:8f5db5085df7 | 47 | |
starling | 0:8f5db5085df7 | 48 | //@{ |
starling | 0:8f5db5085df7 | 49 | ///Angle reference from robot range (in radians). |
starling | 0:8f5db5085df7 | 50 | #define REL_ANG_REF_MIN -PI |
starling | 0:8f5db5085df7 | 51 | #define REL_ANG_REF_MAX PI |
starling | 0:8f5db5085df7 | 52 | //@} |
starling | 0:8f5db5085df7 | 53 | |
starling | 0:8f5db5085df7 | 54 | //@{ |
starling | 0:8f5db5085df7 | 55 | ///Angle reference from magnetometer range (in radians). |
starling | 0:8f5db5085df7 | 56 | #define MAG_ANG_REF_MIN -PI |
starling | 0:8f5db5085df7 | 57 | #define MAG_ANG_REF_MAX PI |
starling | 0:8f5db5085df7 | 58 | //@} |
starling | 0:8f5db5085df7 | 59 | |
starling | 0:8f5db5085df7 | 60 | //@{ |
starling | 0:8f5db5085df7 | 61 | ///Break intensity |
starling | 0:8f5db5085df7 | 62 | #define BRAKE_INTENSITY_MIN 0.0 |
starling | 0:8f5db5085df7 | 63 | #define BRAKE_INTENSITY_MAX 100.0 |
starling | 0:8f5db5085df7 | 64 | //@} |
starling | 0:8f5db5085df7 | 65 | |
starling | 0:8f5db5085df7 | 66 | //@{ |
starling | 0:8f5db5085df7 | 67 | ///Jogging speed ratio. |
starling | 0:8f5db5085df7 | 68 | #define BRAKE_PERIOD_MIN 0.0 |
starling | 0:8f5db5085df7 | 69 | #define BRAKE_PERIOD_MAX 100.0 |
starling | 0:8f5db5085df7 | 70 | //@} |
starling | 0:8f5db5085df7 | 71 | |
starling | 0:8f5db5085df7 | 72 | //@{ |
starling | 0:8f5db5085df7 | 73 | ///Jogging speed period (in seconds). |
starling | 0:8f5db5085df7 | 74 | #define JOG_VEL_PERIOD_MIN 0.0 |
starling | 0:8f5db5085df7 | 75 | #define JOG_VEL_PERIOD_MAX 300.0 |
starling | 0:8f5db5085df7 | 76 | //@} |
starling | 0:8f5db5085df7 | 77 | |
starling | 0:8f5db5085df7 | 78 | //@{ |
starling | 0:8f5db5085df7 | 79 | ///Jogging speed ratio. |
starling | 0:8f5db5085df7 | 80 | #define JOG_VEL_RATIO_MIN 0.0 |
starling | 0:8f5db5085df7 | 81 | #define JOG_VEL_RATIO_MAX 1.0 |
starling | 0:8f5db5085df7 | 82 | //@} |
starling | 0:8f5db5085df7 | 83 | |
starling | 0:8f5db5085df7 | 84 | //@{ |
starling | 0:8f5db5085df7 | 85 | ///Magnetometer calibration values. |
starling | 0:8f5db5085df7 | 86 | #define MAG_CALIB_MIN -750.0 |
starling | 0:8f5db5085df7 | 87 | #define MAG_CALIB_MAX 750.0 |
starling | 0:8f5db5085df7 | 88 | //@} |
starling | 0:8f5db5085df7 | 89 | |
starling | 0:8f5db5085df7 | 90 | ///Messages to send via protocol. |
starling | 0:8f5db5085df7 | 91 | enum |
starling | 0:8f5db5085df7 | 92 | { |
starling | 0:8f5db5085df7 | 93 | ///Do nothing. |
starling | 0:8f5db5085df7 | 94 | NONE, |
starling | 0:8f5db5085df7 | 95 | |
starling | 0:8f5db5085df7 | 96 | ///Brake the robot. |
starling | 0:8f5db5085df7 | 97 | BRAKE, |
starling | 0:8f5db5085df7 | 98 | |
starling | 0:8f5db5085df7 | 99 | ///Reset gyroscope. |
starling | 0:8f5db5085df7 | 100 | GYRO_ZERO, |
starling | 0:8f5db5085df7 | 101 | |
starling | 0:8f5db5085df7 | 102 | ///Set zero axis to current angle measure. |
starling | 0:8f5db5085df7 | 103 | ANG_SET, |
starling | 0:8f5db5085df7 | 104 | |
starling | 0:8f5db5085df7 | 105 | ///Reset angle zero axis. |
starling | 0:8f5db5085df7 | 106 | ANG_RST, |
starling | 0:8f5db5085df7 | 107 | |
starling | 0:8f5db5085df7 | 108 | ///Turn on leds |
starling | 0:8f5db5085df7 | 109 | LED_ON, |
starling | 0:8f5db5085df7 | 110 | |
starling | 0:8f5db5085df7 | 111 | ///Turn off leds |
starling | 0:8f5db5085df7 | 112 | LED_OFF, |
starling | 0:8f5db5085df7 | 113 | |
starling | 0:8f5db5085df7 | 114 | ///Set new angle reference relative to zero axis. |
starling | 0:8f5db5085df7 | 115 | ABS_ANG_REF, |
starling | 0:8f5db5085df7 | 116 | |
starling | 0:8f5db5085df7 | 117 | ///Set new angle reference relative to robot axis. |
starling | 0:8f5db5085df7 | 118 | REL_ANG_REF, |
starling | 0:8f5db5085df7 | 119 | |
starling | 0:8f5db5085df7 | 120 | ///Set new angle reference relative to north using magnetometer. |
starling | 0:8f5db5085df7 | 121 | MAG_ANG_REF, |
starling | 0:8f5db5085df7 | 122 | |
starling | 0:8f5db5085df7 | 123 | ///Set new ground velocity for robot. |
starling | 0:8f5db5085df7 | 124 | GND_VEL, |
starling | 0:8f5db5085df7 | 125 | |
starling | 0:8f5db5085df7 | 126 | ///Set new jogging speed for robot. |
starling | 0:8f5db5085df7 | 127 | JOG_VEL, |
starling | 0:8f5db5085df7 | 128 | |
starling | 0:8f5db5085df7 | 129 | ///Magnetometer calibration (min_x, max_x, min_y, max_y). |
starling | 0:8f5db5085df7 | 130 | MAG_CALIB, |
starling | 0:8f5db5085df7 | 131 | |
starling | 0:8f5db5085df7 | 132 | ///Send PID control parameters (P, I, D, N). |
starling | 0:8f5db5085df7 | 133 | PID_PARAMS |
starling | 0:8f5db5085df7 | 134 | }; |
starling | 0:8f5db5085df7 | 135 | |
starling | 0:8f5db5085df7 | 136 | #define MSG_HEADER_SIZE 1 |
starling | 0:8f5db5085df7 | 137 | #define MSG_VAL_SIZE 2 |
starling | 0:8f5db5085df7 | 138 | #define MSG_MAX_NUM_VALS 4 |
starling | 0:8f5db5085df7 | 139 | #define MSG_BUF_LEN (MSG_HEADER_SIZE + MSG_VAL_SIZE*MSG_MAX_NUM_VALS) |
starling | 0:8f5db5085df7 | 140 | #define MSG_HEADER_IDX 0 |
starling | 0:8f5db5085df7 | 141 | #define MSG_VALS_START_IDX (MSG_HEADER_IDX + 1) |
starling | 0:8f5db5085df7 | 142 | |
starling | 0:8f5db5085df7 | 143 | #define SENDER_PORT 7532 |
starling | 0:8f5db5085df7 | 144 | #define SENDER_IFACE_ADDR "192.168.7.2" |
starling | 0:8f5db5085df7 | 145 | #define SENDER_NETMASK_ADDR "255.255.255.0" |
starling | 0:8f5db5085df7 | 146 | #define SENDER_GATEWAY_ADDR "0.0.0.0" |
starling | 0:8f5db5085df7 | 147 | |
starling | 0:8f5db5085df7 | 148 | #define RECEIVER_PORT 7533 |
starling | 0:8f5db5085df7 | 149 | #define RECEIVER_IFACE_ADDR "192.168.7.3" |
starling | 0:8f5db5085df7 | 150 | #define RECEIVER_NETMASK_ADDR "255.255.255.0" |
starling | 0:8f5db5085df7 | 151 | #define RECEIVER_GATEWAY_ADDR "0.0.0.0" |
starling | 0:8f5db5085df7 | 152 | |
starling | 0:8f5db5085df7 | 153 | #endif |
starling | 0:8f5db5085df7 | 154 |