![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
This program is for an autonomous robot for the competition at the Hochschule Luzern. http://cruisingcrepe.wordpress.com/ We are one of the 32 teams. http://cruisingcrepe.wordpress.com/ The postition control is based on this Documentation: Control of Wheeled Mobile Robots: An Experimental Overview from Alessandro De Luca, Giuseppe Oriolo, Marilena Vendittelli. For more information see here: http://www.dis.uniroma1.it/~labrob/pub/papers/Ramsete01.pdf
Fork of autonomous Robot Android by
MicroBridge/PacketBuffer/PacketBuffer.cpp@18:306d362d692b, 2013-05-03 (annotated)
- Committer:
- chrigelburri
- Date:
- Fri May 03 08:35:29 2013 +0000
- Revision:
- 18:306d362d692b
androidADB successfully linking
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chrigelburri | 18:306d362d692b | 1 | |
chrigelburri | 18:306d362d692b | 2 | /** @file PacketBuffer.cpp |
chrigelburri | 18:306d362d692b | 3 | * @brief Ring Buffer |
chrigelburri | 18:306d362d692b | 4 | */ |
chrigelburri | 18:306d362d692b | 5 | |
chrigelburri | 18:306d362d692b | 6 | #include "PacketBuffer.h" |
chrigelburri | 18:306d362d692b | 7 | |
chrigelburri | 18:306d362d692b | 8 | |
chrigelburri | 18:306d362d692b | 9 | PacketBuffer::PacketBuffer(int num,int packet_size) |
chrigelburri | 18:306d362d692b | 10 | { |
chrigelburri | 18:306d362d692b | 11 | max_num = num; |
chrigelburri | 18:306d362d692b | 12 | max_size = packet_size; |
chrigelburri | 18:306d362d692b | 13 | |
chrigelburri | 18:306d362d692b | 14 | p_buf = new PacketBufInf[num]; |
chrigelburri | 18:306d362d692b | 15 | |
chrigelburri | 18:306d362d692b | 16 | for(int i = 0 ; i < num ; i++) |
chrigelburri | 18:306d362d692b | 17 | { |
chrigelburri | 18:306d362d692b | 18 | p_buf[i].buf = new char[packet_size]; |
chrigelburri | 18:306d362d692b | 19 | p_buf[i].size = 0; |
chrigelburri | 18:306d362d692b | 20 | } |
chrigelburri | 18:306d362d692b | 21 | addr_w = 0; |
chrigelburri | 18:306d362d692b | 22 | addr_r = 0; |
chrigelburri | 18:306d362d692b | 23 | } |
chrigelburri | 18:306d362d692b | 24 | |
chrigelburri | 18:306d362d692b | 25 | PacketBuffer::~PacketBuffer() |
chrigelburri | 18:306d362d692b | 26 | { |
chrigelburri | 18:306d362d692b | 27 | |
chrigelburri | 18:306d362d692b | 28 | for(int i = 0 ; i < max_num ; i++) |
chrigelburri | 18:306d362d692b | 29 | { |
chrigelburri | 18:306d362d692b | 30 | delete [] p_buf[i].buf; |
chrigelburri | 18:306d362d692b | 31 | } |
chrigelburri | 18:306d362d692b | 32 | delete [] p_buf; |
chrigelburri | 18:306d362d692b | 33 | } |
chrigelburri | 18:306d362d692b | 34 | |
chrigelburri | 18:306d362d692b | 35 | int PacketBuffer::PutPacket(char *packet, int len) |
chrigelburri | 18:306d362d692b | 36 | { |
chrigelburri | 18:306d362d692b | 37 | int next; |
chrigelburri | 18:306d362d692b | 38 | |
chrigelburri | 18:306d362d692b | 39 | if(max_size < len) return(-1); |
chrigelburri | 18:306d362d692b | 40 | |
chrigelburri | 18:306d362d692b | 41 | next = (addr_w + 1) % max_num; |
chrigelburri | 18:306d362d692b | 42 | |
chrigelburri | 18:306d362d692b | 43 | if( next == addr_r ) return(0); |
chrigelburri | 18:306d362d692b | 44 | |
chrigelburri | 18:306d362d692b | 45 | memcpy( p_buf[addr_w].buf , packet , len ); |
chrigelburri | 18:306d362d692b | 46 | |
chrigelburri | 18:306d362d692b | 47 | p_buf[addr_w].size = len; |
chrigelburri | 18:306d362d692b | 48 | |
chrigelburri | 18:306d362d692b | 49 | addr_w = next; |
chrigelburri | 18:306d362d692b | 50 | |
chrigelburri | 18:306d362d692b | 51 | return(len); |
chrigelburri | 18:306d362d692b | 52 | } |
chrigelburri | 18:306d362d692b | 53 | |
chrigelburri | 18:306d362d692b | 54 | int PacketBuffer::GetPacket(char *packet) |
chrigelburri | 18:306d362d692b | 55 | { |
chrigelburri | 18:306d362d692b | 56 | int len; |
chrigelburri | 18:306d362d692b | 57 | |
chrigelburri | 18:306d362d692b | 58 | if( addr_w == addr_r ) return(0); |
chrigelburri | 18:306d362d692b | 59 | |
chrigelburri | 18:306d362d692b | 60 | len = p_buf[addr_r].size; |
chrigelburri | 18:306d362d692b | 61 | |
chrigelburri | 18:306d362d692b | 62 | memcpy( packet , p_buf[addr_r].buf , len ); |
chrigelburri | 18:306d362d692b | 63 | |
chrigelburri | 18:306d362d692b | 64 | addr_r = (addr_r + 1) % max_num; |
chrigelburri | 18:306d362d692b | 65 | |
chrigelburri | 18:306d362d692b | 66 | return len; |
chrigelburri | 18:306d362d692b | 67 | } |
chrigelburri | 18:306d362d692b | 68 | |
chrigelburri | 18:306d362d692b | 69 | int PacketBuffer::available () { |
chrigelburri | 18:306d362d692b | 70 | if (addr_w < addr_r) { |
chrigelburri | 18:306d362d692b | 71 | return addr_r - addr_w - 1; |
chrigelburri | 18:306d362d692b | 72 | } else { |
chrigelburri | 18:306d362d692b | 73 | return (max_num - addr_w) + addr_r - 1; |
chrigelburri | 18:306d362d692b | 74 | } |
chrigelburri | 18:306d362d692b | 75 | } |
chrigelburri | 18:306d362d692b | 76 | |
chrigelburri | 18:306d362d692b | 77 | int PacketBuffer::use () { |
chrigelburri | 18:306d362d692b | 78 | return max_num - available() - 1; |
chrigelburri | 18:306d362d692b | 79 | } |
chrigelburri | 18:306d362d692b | 80 | |
chrigelburri | 18:306d362d692b | 81 | void PacketBuffer::clear () { |
chrigelburri | 18:306d362d692b | 82 | addr_w = 0; |
chrigelburri | 18:306d362d692b | 83 | addr_r = 0; |
chrigelburri | 18:306d362d692b | 84 | } |