Revision 1443

View differences:

trunk/code/projects/libwireless/lib/wl_token_ring.c
738 738
 **/
739 739
static void wl_token_bom_on_receive(int source)
740 740
{
741
	int max, dist;
742

  
741 743
	WL_DEBUG_PRINT("Robot ");
742 744
	WL_DEBUG_PRINT_INT(source);
743 745
	WL_DEBUG_PRINT(" has flashed its bom.\r\n");
744 746

  
745 747
	bom_on_count = 0;
746 748

  
749
	max = get_max_bom_function();
747 750
	sensor_matrix_set_reading(wl_get_xbee_id(),
748
		source, get_max_bom_function());
751
		source, max);
752

  
753
	WL_DEBUG_PRINT("Max: ");
754
	WL_DEBUG_PRINT_INT(max);
755
	WL_DEBUG_PRINT("\tVar: ");
756
	WL_DEBUG_PRINT_INT(dist);
757
	WL_DEBUG_PRINT("\n\n");
749 758
}
750 759

  
751 760
/**
trunk/code/projects/libwireless/lib/xbee.c
47 47

  
48 48
#include <serial.h>
49 49
#include <avr/interrupt.h>
50
#include <util/delay.h>
50 51

  
51 52
#endif
52 53

  
......
584 585
}
585 586

  
586 587
/**
588
 * Resets the XBee Modem (including baud rate when on robot)
589
 * 
590
 * Used for launching bootloader
591
 **/
592
int xbee_reset(void)
593
{
594
#ifdef ROBOT
595
	xbee_send_modify_at_command("BD", "3");
596
#endif
597
	xbee_send_read_at_command("FR");
598
    // delay 150 ms to wait for reset
599
#ifndef ROBOT
600
	usleep(150000);
601
#else
602
	_delay_ms(150);
603
#endif
604

  
605
	return 0;
606
}
607

  
608
/**
587 609
 * Sends an AT command to read a parameter.
588 610
 *
589 611
 * @param command the AT command to send. For exmaple,
trunk/code/projects/libwireless/lib/xbee.h
93 93
unsigned int xbee_get_address(void);
94 94
/**@brief Set the com port on a computer, undefined on the robot**/
95 95
void xbee_set_com_port(char* port);
96
/**@brief Reset XBee **/
97
int xbee_reset(void);
96 98

  
97 99
/**@}**/ //end defgroup
98 100

  
trunk/code/projects/wireless_bootloader/bootloader_launch.c
1
#include "xbee.h"
2
#include <avr/interrupt.h>
3

  
4
#define BOOTLOADER_ADDR     0x0001e756
5

  
6
int (*bootloader)(int force) = (void*)BOOTLOADER_ADDR;
7

  
8
int launch_bootloader(void)
9
{
10
    cli();
11
    xbee_reset();
12
    bootloader(1);
13
}
trunk/code/projects/libdragonfly/bom.c
226 226
        return lowest_i;
227 227
    else
228 228
        return -1;
229
}
230

  
231
/** 
232
 * Computes the weighted average of all the bom readings to estimate the position (and distance) of another robot.
233
 *
234
 * @pre must call bom refresh
235
 * @param dist  pointer to int in which to return the estimated distance to the other robot
236
 * @return estimated position of the max bom value element as a fixed point value analogous to 10 times the
237
 *        index of the max bom value.  -1 if no value is lower than BOM_VALUE_THRESHOLD.
238
 **/
239
int bom_get_max10(int *dist) {
240
    int i, max;
241
    long long mean, sum;
242

  
243
    max = bom_get_max();
244
    if (max < 0)
245
    {
246
        if (dist)
247
        {
248
            *dist = -1;
249
        }
250
        return -1;
251
    }
252
    /* Record values into an array */
253
    for (i = 0; i < NUM_BOM_LEDS; i++) {
254
        int idx = ((i + (NUM_BOM_LEDS/2 - max) + NUM_BOM_LEDS) % NUM_BOM_LEDS) - (NUM_BOM_LEDS/2 - max);
255
        int val = 255 - bom_val[i];
256
        mean += idx * val;
257
        sum += val;
258
    }
259
    mean = (mean * 10) / sum;
260
    mean = (mean + NUM_BOM_LEDS*10) % (NUM_BOM_LEDS*10);
261

  
262
    if (dist)
263
    {
264
        *dist = 50 - sum/48;
265
    }
266

  
267
    return mean;
229 268
}
230 269

  
231 270
/**
trunk/code/projects/libdragonfly/bom.h
68 68
/** @brief Compares all the values in bom_val[] and returns the index to the highest value element. **/
69 69
int bom_get_max(void);
70 70

  
71
/** @brief Computes the weighted average of all the bom readings to estimate the position and distance of another robot. **/
72
int bom_get_max10(int *dist);
73

  
71 74
/** @brief Enables the selected bom leds on a BOM1.5 **/
72 75
void bom_set_leds(int bit_field);
73 76

  

Also available in: Unified diff