This is a Transmitter Code. Design and development of a wireless Robotic Arm that mirrors the movement of a hand in the horizontal and vertical direction. For this purpose, we have used FRDMk64F on board accelerometer that collects raw motion in terms of horizontal and vertical axis, processes it and sends it to another FRDM K64F wirelessly. On the other side this FRDM K64F processes the received data and sends a command to servo motor that moves the arms in the direction such a that it imitates the user’s hand.
Dependencies: DebounceIn FXOS8700Q mbed nRF24L01P
APPARATUS
1. Freescale development board – FRDM K64F
2. Servo Motors (3V to 6 V) DC
3. nRF24L01 – Wireless Trans-receiver
4. Gloves
5. USB cable
6. Gloves
7. Robotic arm MICROBOTLABS
main.cpp@0:c768464c8cbc, 2016-05-09 (annotated)
- Committer:
- nrrathi
- Date:
- Mon May 09 15:55:28 2016 +0000
- Revision:
- 0:c768464c8cbc
A type of programmable mechanical arm, with similar functions to a human arm.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nrrathi | 0:c768464c8cbc | 1 | #include "mbed.h" |
nrrathi | 0:c768464c8cbc | 2 | #include "nRF24L01P.h" |
nrrathi | 0:c768464c8cbc | 3 | #include "FXOS8700Q.h" |
nrrathi | 0:c768464c8cbc | 4 | #include "DebounceIn.h" |
nrrathi | 0:c768464c8cbc | 5 | |
nrrathi | 0:c768464c8cbc | 6 | #define ACC_SAMPLE_SIZE 200 |
nrrathi | 0:c768464c8cbc | 7 | #define ACC_X_GAIN 1 |
nrrathi | 0:c768464c8cbc | 8 | #define ACC_Y_GAIN 2 |
nrrathi | 0:c768464c8cbc | 9 | #define TRANSFER_SIZE 9 |
nrrathi | 0:c768464c8cbc | 10 | |
nrrathi | 0:c768464c8cbc | 11 | Serial pc(USBTX, USBRX); // tx, rx |
nrrathi | 0:c768464c8cbc | 12 | |
nrrathi | 0:c768464c8cbc | 13 | nRF24L01P my_nrf24l01p(PTD6, PTD7, PTD5, PTD4, PTC12, PTC18); // mosi, miso, sck, csn, ce, irq |
nrrathi | 0:c768464c8cbc | 14 | FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board |
nrrathi | 0:c768464c8cbc | 15 | |
nrrathi | 0:c768464c8cbc | 16 | DigitalOut myled1(LED1); |
nrrathi | 0:c768464c8cbc | 17 | DigitalOut myled2(LED2); |
nrrathi | 0:c768464c8cbc | 18 | DigitalOut myled3(LED3); |
nrrathi | 0:c768464c8cbc | 19 | MotionSensorDataCounts acc_raw; |
nrrathi | 0:c768464c8cbc | 20 | int16_t acc_x, acc_y; |
nrrathi | 0:c768464c8cbc | 21 | DebounceIn cal_button(PTC6); |
nrrathi | 0:c768464c8cbc | 22 | |
nrrathi | 0:c768464c8cbc | 23 | int main() |
nrrathi | 0:c768464c8cbc | 24 | { |
nrrathi | 0:c768464c8cbc | 25 | |
nrrathi | 0:c768464c8cbc | 26 | char txData[TRANSFER_SIZE]; |
nrrathi | 0:c768464c8cbc | 27 | int txDataCnt = 0; |
nrrathi | 0:c768464c8cbc | 28 | |
nrrathi | 0:c768464c8cbc | 29 | int acc_x_array[ACC_SAMPLE_SIZE]; |
nrrathi | 0:c768464c8cbc | 30 | int acc_y_array[ACC_SAMPLE_SIZE]; |
nrrathi | 0:c768464c8cbc | 31 | int acc_sample_cnt = 0; |
nrrathi | 0:c768464c8cbc | 32 | |
nrrathi | 0:c768464c8cbc | 33 | int acc_x_avg = 0; |
nrrathi | 0:c768464c8cbc | 34 | int acc_y_avg = 0; |
nrrathi | 0:c768464c8cbc | 35 | |
nrrathi | 0:c768464c8cbc | 36 | int acc_x_cal = 0; |
nrrathi | 0:c768464c8cbc | 37 | int acc_y_cal = 0; |
nrrathi | 0:c768464c8cbc | 38 | |
nrrathi | 0:c768464c8cbc | 39 | pc.baud(115200); |
nrrathi | 0:c768464c8cbc | 40 | |
nrrathi | 0:c768464c8cbc | 41 | my_nrf24l01p.setTxAddress(0xDEADBEEF0F); |
nrrathi | 0:c768464c8cbc | 42 | my_nrf24l01p.powerUp(); |
nrrathi | 0:c768464c8cbc | 43 | myled1 = 1; |
nrrathi | 0:c768464c8cbc | 44 | myled2 = 1; |
nrrathi | 0:c768464c8cbc | 45 | |
nrrathi | 0:c768464c8cbc | 46 | pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); |
nrrathi | 0:c768464c8cbc | 47 | pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); |
nrrathi | 0:c768464c8cbc | 48 | pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); |
nrrathi | 0:c768464c8cbc | 49 | pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() ); |
nrrathi | 0:c768464c8cbc | 50 | pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() ); |
nrrathi | 0:c768464c8cbc | 51 | |
nrrathi | 0:c768464c8cbc | 52 | my_nrf24l01p.setTransferSize( TRANSFER_SIZE ); |
nrrathi | 0:c768464c8cbc | 53 | my_nrf24l01p.enable(); |
nrrathi | 0:c768464c8cbc | 54 | |
nrrathi | 0:c768464c8cbc | 55 | acc.enable(); |
nrrathi | 0:c768464c8cbc | 56 | |
nrrathi | 0:c768464c8cbc | 57 | myled3 = 0; |
nrrathi | 0:c768464c8cbc | 58 | |
nrrathi | 0:c768464c8cbc | 59 | for (int x=0; x<ACC_SAMPLE_SIZE; x++) |
nrrathi | 0:c768464c8cbc | 60 | { |
nrrathi | 0:c768464c8cbc | 61 | acc_x_array[x]=0; |
nrrathi | 0:c768464c8cbc | 62 | acc_y_array[x]=0; |
nrrathi | 0:c768464c8cbc | 63 | } |
nrrathi | 0:c768464c8cbc | 64 | |
nrrathi | 0:c768464c8cbc | 65 | while (1) |
nrrathi | 0:c768464c8cbc | 66 | { |
nrrathi | 0:c768464c8cbc | 67 | acc.getAxis(acc_raw); |
nrrathi | 0:c768464c8cbc | 68 | |
nrrathi | 0:c768464c8cbc | 69 | acc_x = acc_raw.x - acc_x_cal; |
nrrathi | 0:c768464c8cbc | 70 | acc_y = acc_raw.y - acc_y_cal; |
nrrathi | 0:c768464c8cbc | 71 | |
nrrathi | 0:c768464c8cbc | 72 | acc_x_array[acc_sample_cnt]=(int)(acc_x>>2); |
nrrathi | 0:c768464c8cbc | 73 | acc_y_array[acc_sample_cnt]=(int)(acc_y>>2); |
nrrathi | 0:c768464c8cbc | 74 | |
nrrathi | 0:c768464c8cbc | 75 | acc_sample_cnt++; |
nrrathi | 0:c768464c8cbc | 76 | if (acc_sample_cnt>=ACC_SAMPLE_SIZE) acc_sample_cnt = 0; |
nrrathi | 0:c768464c8cbc | 77 | |
nrrathi | 0:c768464c8cbc | 78 | acc_x_avg=0; |
nrrathi | 0:c768464c8cbc | 79 | acc_y_avg=0; |
nrrathi | 0:c768464c8cbc | 80 | for (int x=0; x<ACC_SAMPLE_SIZE; x++) |
nrrathi | 0:c768464c8cbc | 81 | { |
nrrathi | 0:c768464c8cbc | 82 | acc_x_avg=acc_x_avg+acc_x_array[x]; |
nrrathi | 0:c768464c8cbc | 83 | acc_y_avg=acc_y_avg+acc_y_array[x]; |
nrrathi | 0:c768464c8cbc | 84 | } |
nrrathi | 0:c768464c8cbc | 85 | acc_x_avg = (int)(acc_x_avg/ACC_SAMPLE_SIZE); |
nrrathi | 0:c768464c8cbc | 86 | acc_y_avg = (int)(acc_y_avg/ACC_SAMPLE_SIZE); |
nrrathi | 0:c768464c8cbc | 87 | |
nrrathi | 0:c768464c8cbc | 88 | pc.printf("%d (%d)\t%d (%d)\n\r",acc_x_avg,acc_raw.x,acc_y_avg,acc_raw.y); |
nrrathi | 0:c768464c8cbc | 89 | |
nrrathi | 0:c768464c8cbc | 90 | txData[0] = (acc_x_avg) & 0xff; |
nrrathi | 0:c768464c8cbc | 91 | txData[1] = (acc_x_avg>>8) & 0xff; |
nrrathi | 0:c768464c8cbc | 92 | txData[2] = (acc_x_avg>>16) & 0xff; |
nrrathi | 0:c768464c8cbc | 93 | txData[3] = (acc_x_avg>>24) & 0xff; |
nrrathi | 0:c768464c8cbc | 94 | |
nrrathi | 0:c768464c8cbc | 95 | txData[4] = (acc_y_avg) & 0xff; |
nrrathi | 0:c768464c8cbc | 96 | txData[5] = (acc_y_avg>>8) & 0xff; |
nrrathi | 0:c768464c8cbc | 97 | txData[6] = (acc_y_avg>>16) & 0xff; |
nrrathi | 0:c768464c8cbc | 98 | txData[7] = (acc_y_avg>>24) & 0xff; |
nrrathi | 0:c768464c8cbc | 99 | |
nrrathi | 0:c768464c8cbc | 100 | my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, sizeof( txData ) ); |
nrrathi | 0:c768464c8cbc | 101 | pc.printf("sent data to rx"); |
nrrathi | 0:c768464c8cbc | 102 | |
nrrathi | 0:c768464c8cbc | 103 | wait(0.001); |
nrrathi | 0:c768464c8cbc | 104 | |
nrrathi | 0:c768464c8cbc | 105 | if (cal_button.read()==0) |
nrrathi | 0:c768464c8cbc | 106 | { |
nrrathi | 0:c768464c8cbc | 107 | myled2 = 0; |
nrrathi | 0:c768464c8cbc | 108 | myled3 = 1; |
nrrathi | 0:c768464c8cbc | 109 | |
nrrathi | 0:c768464c8cbc | 110 | acc_x_avg=0; |
nrrathi | 0:c768464c8cbc | 111 | acc_y_avg=0; |
nrrathi | 0:c768464c8cbc | 112 | for (int x=0; x<ACC_SAMPLE_SIZE; x++) |
nrrathi | 0:c768464c8cbc | 113 | { |
nrrathi | 0:c768464c8cbc | 114 | acc.getAxis(acc_raw); |
nrrathi | 0:c768464c8cbc | 115 | acc_x_avg=acc_x_avg+acc_raw.x; |
nrrathi | 0:c768464c8cbc | 116 | acc_y_avg=acc_y_avg+acc_raw.y; |
nrrathi | 0:c768464c8cbc | 117 | wait(0.01); |
nrrathi | 0:c768464c8cbc | 118 | } |
nrrathi | 0:c768464c8cbc | 119 | acc_x_cal = (int)(acc_x_avg/ACC_SAMPLE_SIZE); |
nrrathi | 0:c768464c8cbc | 120 | acc_y_cal = (int)(acc_y_avg/ACC_SAMPLE_SIZE); |
nrrathi | 0:c768464c8cbc | 121 | myled2 = 1; |
nrrathi | 0:c768464c8cbc | 122 | myled3 = 0; |
nrrathi | 0:c768464c8cbc | 123 | } |
nrrathi | 0:c768464c8cbc | 124 | |
nrrathi | 0:c768464c8cbc | 125 | } |
nrrathi | 0:c768464c8cbc | 126 | } |