Raúl de Santos Rico
/
LacqueyFetch
LacqueyFetch firmware for the mbed
main.cpp@1:3b3e8f8352a8, 2018-04-03 (annotated)
- Committer:
- raulsr988
- Date:
- Tue Apr 03 15:11:02 2018 +0000
- Revision:
- 1:3b3e8f8352a8
- Parent:
- 0:f8a72cc60181
- Child:
- 2:8ebb11ba21be
correcting some documentation notes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
raulsr988 | 0:f8a72cc60181 | 1 | /** |
raulsr988 | 0:f8a72cc60181 | 2 | * |
raulsr988 | 0:f8a72cc60181 | 3 | * @ingroup teo_body_lacqueyFetch |
raulsr988 | 0:f8a72cc60181 | 4 | * \defgroup teo_body_MbedFirmware Mbed-Firmware |
raulsr988 | 0:f8a72cc60181 | 5 | * |
raulsr988 | 0:f8a72cc60181 | 6 | * @brief Firmware that allows to recieve CAN messages to open and close the hand |
raulsr988 | 0:f8a72cc60181 | 7 | * |
raulsr988 | 0:f8a72cc60181 | 8 | * @section teo_body_firmware_legal Legal |
raulsr988 | 0:f8a72cc60181 | 9 | * |
raulsr988 | 0:f8a72cc60181 | 10 | * Copyright: 2018 (C) Universidad Carlos III de Madrid |
raulsr988 | 0:f8a72cc60181 | 11 | * |
raulsr988 | 0:f8a72cc60181 | 12 | * Author: <a href="http://roboticslab.uc3m.es/roboticslab/people/r-de-santos">Raul de Santos Rico</a> |
raulsr988 | 0:f8a72cc60181 | 13 | * |
raulsr988 | 0:f8a72cc60181 | 14 | * CopyPolicy: Released under the terms of the LGPLv2.1 or later, see license/LGPL.TXT |
raulsr988 | 0:f8a72cc60181 | 15 | * |
raulsr988 | 0:f8a72cc60181 | 16 | * @section lacqueyFetch_install Installation |
raulsr988 | 0:f8a72cc60181 | 17 | * |
raulsr988 | 1:3b3e8f8352a8 | 18 | * First you need to program the firmware to the MBED <br> |
raulsr988 | 0:f8a72cc60181 | 19 | * You can use the online compiler (https://os.mbed.com/compiler) to compile the firmware and stored it on the flash mbed memory<br> |
raulsr988 | 0:f8a72cc60181 | 20 | * Steps: |
raulsr988 | 0:f8a72cc60181 | 21 | * - Change the "id" of the device corresponding to the hand used (right-hand: ID 65, left-hand: ID 64) <br> |
raulsr988 | 1:3b3e8f8352a8 | 22 | * - Press "Compile" and save the .bin file on the flash mbed memory <br> |
raulsr988 | 0:f8a72cc60181 | 23 | * - If you want to check the correct functionality, you can connect the mbed to the serial USB and with a serial monitor program (configured with a baudrate of 115200), see the CAN messages information of the hand. <br> |
raulsr988 | 0:f8a72cc60181 | 24 | * |
raulsr988 | 0:f8a72cc60181 | 25 | * |
raulsr988 | 1:3b3e8f8352a8 | 26 | * @section lacqueyFetch_running Running (assuming correct installation) |
raulsr988 | 0:f8a72cc60181 | 27 | * |
raulsr988 | 1:3b3e8f8352a8 | 28 | * Running "launchManipulation" application, you can open or close the hand with this parameters (assuming you know how to run "launchManipulation"): <br> |
raulsr988 | 1:3b3e8f8352a8 | 29 | * set pos 6 1 -> open hand <br> |
raulsr988 | 1:3b3e8f8352a8 | 30 | * set pos 6 -1 -> close hand <br> |
raulsr988 | 1:3b3e8f8352a8 | 31 | * set pos 6 0 -> loose hand <br> |
raulsr988 | 0:f8a72cc60181 | 32 | * |
raulsr988 | 0:f8a72cc60181 | 33 | **/ |
raulsr988 | 0:f8a72cc60181 | 34 | |
raulsr988 | 0:f8a72cc60181 | 35 | #include "mbed.h" |
raulsr988 | 0:f8a72cc60181 | 36 | #include "Motor.h" |
raulsr988 | 0:f8a72cc60181 | 37 | |
raulsr988 | 0:f8a72cc60181 | 38 | Serial pc(USBTX, USBRX); // Serial connection |
raulsr988 | 0:f8a72cc60181 | 39 | DigitalOut led1(LED1); // received |
raulsr988 | 0:f8a72cc60181 | 40 | CAN can(p30, p29); // tx,rx |
raulsr988 | 0:f8a72cc60181 | 41 | Motor m(p24, p26, p25); // pwm, fwd, rev (PWM, REVERSE, FORDWARD) |
raulsr988 | 0:f8a72cc60181 | 42 | |
raulsr988 | 0:f8a72cc60181 | 43 | |
raulsr988 | 0:f8a72cc60181 | 44 | bool receive(signed char* order) { |
raulsr988 | 0:f8a72cc60181 | 45 | int8_t id = 65; // right-hand: ID 65, left-hand: ID 64 |
raulsr988 | 0:f8a72cc60181 | 46 | signed char data; |
raulsr988 | 0:f8a72cc60181 | 47 | CANMessage msg; |
raulsr988 | 0:f8a72cc60181 | 48 | if( can.read(msg) ) { |
raulsr988 | 0:f8a72cc60181 | 49 | if(id == (int8_t)msg.id){ |
raulsr988 | 0:f8a72cc60181 | 50 | pc.printf("Message received (ID: %d) (size: %d)\n", (int8_t)msg.id, msg.len); |
raulsr988 | 0:f8a72cc60181 | 51 | data = msg.data[0]; |
raulsr988 | 0:f8a72cc60181 | 52 | *order = data; |
raulsr988 | 0:f8a72cc60181 | 53 | led1 = !led1; |
raulsr988 | 0:f8a72cc60181 | 54 | return true; |
raulsr988 | 0:f8a72cc60181 | 55 | } |
raulsr988 | 0:f8a72cc60181 | 56 | } |
raulsr988 | 0:f8a72cc60181 | 57 | |
raulsr988 | 0:f8a72cc60181 | 58 | return false; |
raulsr988 | 0:f8a72cc60181 | 59 | } |
raulsr988 | 0:f8a72cc60181 | 60 | |
raulsr988 | 0:f8a72cc60181 | 61 | int main() { |
raulsr988 | 0:f8a72cc60181 | 62 | // set up the serial usb connection |
raulsr988 | 0:f8a72cc60181 | 63 | pc.baud(115200); //-- configure PC baudrate |
raulsr988 | 0:f8a72cc60181 | 64 | pc.printf("main()\n"); |
raulsr988 | 0:f8a72cc60181 | 65 | // set up the can bus |
raulsr988 | 0:f8a72cc60181 | 66 | can.frequency(1000000); //-- 1Mbit/s (the same as the drivers configuration) |
raulsr988 | 0:f8a72cc60181 | 67 | can.reset(); |
raulsr988 | 0:f8a72cc60181 | 68 | |
raulsr988 | 0:f8a72cc60181 | 69 | // message received |
raulsr988 | 0:f8a72cc60181 | 70 | signed char data; |
raulsr988 | 0:f8a72cc60181 | 71 | |
raulsr988 | 0:f8a72cc60181 | 72 | while(1) { |
raulsr988 | 0:f8a72cc60181 | 73 | |
raulsr988 | 0:f8a72cc60181 | 74 | if(receive(&data)) { |
raulsr988 | 0:f8a72cc60181 | 75 | pc.printf("value received: %f\n", (double)data); |
raulsr988 | 0:f8a72cc60181 | 76 | m.speed((double)data); |
raulsr988 | 0:f8a72cc60181 | 77 | } |
raulsr988 | 0:f8a72cc60181 | 78 | } |
raulsr988 | 0:f8a72cc60181 | 79 | } |