DRのPS3での操作用(アームの開閉をコントローラで制御可能)

Dependencies:   mbed CalPID motorout ros_lib_melodic MotorController_AbsEC

Committer:
koheim
Date:
Fri Jul 30 11:36:46 2021 +0000
Revision:
12:c2bb0a9587b5
Parent:
0:83b2c6a67cce
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ayu13 0:83b2c6a67cce 1 /* mbed Microcontroller Library - SerialHalfDuplex
ayu13 0:83b2c6a67cce 2 * Copyright (c) 2010-2011 ARM Limited. All rights reserved.
ayu13 0:83b2c6a67cce 3 */
ayu13 0:83b2c6a67cce 4 #ifndef MBED_SERIALHALFDUPLEX_H
ayu13 0:83b2c6a67cce 5 #define MBED_SERIALHALFDUPLEX_H
ayu13 0:83b2c6a67cce 6
ayu13 0:83b2c6a67cce 7 #include "platform.h"
ayu13 0:83b2c6a67cce 8
ayu13 0:83b2c6a67cce 9 #if DEVICE_SERIAL
ayu13 0:83b2c6a67cce 10
ayu13 0:83b2c6a67cce 11 #include "Serial.h"
ayu13 0:83b2c6a67cce 12
ayu13 0:83b2c6a67cce 13 namespace mbed {
ayu13 0:83b2c6a67cce 14
ayu13 0:83b2c6a67cce 15 /** A serial port (UART) for communication with other devices using
ayu13 0:83b2c6a67cce 16 * Half-Duplex, allowing transmit and receive on a single
ayu13 0:83b2c6a67cce 17 * shared transmit and receive line. Only one end should be transmitting
ayu13 0:83b2c6a67cce 18 * at a time.
ayu13 0:83b2c6a67cce 19 *
ayu13 0:83b2c6a67cce 20 * Both the tx and rx pin should be defined, and wired together.
ayu13 0:83b2c6a67cce 21 * This is in addition to them being wired to the other serial
ayu13 0:83b2c6a67cce 22 * device to allow both read and write functions to operate.
ayu13 0:83b2c6a67cce 23 *
ayu13 0:83b2c6a67cce 24 * For Simplex and Full-Duplex Serial communication, see Serial()
ayu13 0:83b2c6a67cce 25 *
ayu13 0:83b2c6a67cce 26 * Example:
ayu13 0:83b2c6a67cce 27 * @code
ayu13 0:83b2c6a67cce 28 * // Send a byte to a second HalfDuplex device, and read the response
ayu13 0:83b2c6a67cce 29 *
ayu13 0:83b2c6a67cce 30 * #include "mbed.h"
ayu13 0:83b2c6a67cce 31 *
ayu13 0:83b2c6a67cce 32 * // p9 and p10 should be wired together to form "a"
ayu13 0:83b2c6a67cce 33 * // p28 and p27 should be wired together to form "b"
ayu13 0:83b2c6a67cce 34 * // p9/p10 should be wired to p28/p27 as the Half Duplex connection
ayu13 0:83b2c6a67cce 35 *
ayu13 0:83b2c6a67cce 36 * SerialHalfDuplex a(p9, p10);
ayu13 0:83b2c6a67cce 37 * SerialHalfDuplex b(p28, p27);
ayu13 0:83b2c6a67cce 38 *
ayu13 0:83b2c6a67cce 39 * void b_rx() { // second device response
ayu13 0:83b2c6a67cce 40 * b.putc(b.getc() + 4);
ayu13 0:83b2c6a67cce 41 * }
ayu13 0:83b2c6a67cce 42 *
ayu13 0:83b2c6a67cce 43 * int main() {
ayu13 0:83b2c6a67cce 44 * b.attach(&b_rx);
ayu13 0:83b2c6a67cce 45 * for (int c = 'A'; c < 'Z'; c++) {
ayu13 0:83b2c6a67cce 46 * a.putc(c);
ayu13 0:83b2c6a67cce 47 * printf("sent [%c]\n", c);
ayu13 0:83b2c6a67cce 48 * wait(0.5); // b should respond
ayu13 0:83b2c6a67cce 49 * if (a.readable()) {
ayu13 0:83b2c6a67cce 50 * printf("received [%c]\n", a.getc());
ayu13 0:83b2c6a67cce 51 * }
ayu13 0:83b2c6a67cce 52 * }
ayu13 0:83b2c6a67cce 53 * }
ayu13 0:83b2c6a67cce 54 * @endcode
ayu13 0:83b2c6a67cce 55 */
ayu13 0:83b2c6a67cce 56 class SerialHalfDuplex : public Serial {
ayu13 0:83b2c6a67cce 57
ayu13 0:83b2c6a67cce 58 public:
ayu13 0:83b2c6a67cce 59
ayu13 0:83b2c6a67cce 60 /** Create a half-duplex serial port, connected to the specified transmit
ayu13 0:83b2c6a67cce 61 * and receive pins.
ayu13 0:83b2c6a67cce 62 *
ayu13 0:83b2c6a67cce 63 * These pins should be wired together, as well as to the target device
ayu13 0:83b2c6a67cce 64 *
ayu13 0:83b2c6a67cce 65 * @param tx Transmit pin
ayu13 0:83b2c6a67cce 66 * @param rx Receive pin
ayu13 0:83b2c6a67cce 67 *
ayu13 0:83b2c6a67cce 68 * @note
ayu13 0:83b2c6a67cce 69 * Either tx or rx may be specified as NC if unused
ayu13 0:83b2c6a67cce 70 */
ayu13 0:83b2c6a67cce 71 SerialHalfDuplex(PinName tx, PinName rx, const char *name=NULL);
ayu13 0:83b2c6a67cce 72
ayu13 0:83b2c6a67cce 73 protected:
ayu13 0:83b2c6a67cce 74
ayu13 0:83b2c6a67cce 75 virtual int _putc(int c);
ayu13 0:83b2c6a67cce 76 virtual int _getc(void);
ayu13 0:83b2c6a67cce 77
ayu13 0:83b2c6a67cce 78 }; // End class SerialHalfDuplex
ayu13 0:83b2c6a67cce 79
ayu13 0:83b2c6a67cce 80 } // End namespace
ayu13 0:83b2c6a67cce 81
ayu13 0:83b2c6a67cce 82 #endif
ayu13 0:83b2c6a67cce 83
ayu13 0:83b2c6a67cce 84 #endif