Commit from zer0 (2008-01-09 23:24 CET) ================ Add barrel and roller handling
aversive_projects microb2008/extension/.config 1.6 aversive_projects microb2008/extension/Makefile 1.3 + aversive_projects microb2008/extension/encoders_microb_config.h 1.1 aversive_projects microb2008/extension/i2c_protocol.c 1.6 aversive_projects microb2008/extension/main.c 1.9 aversive_projects microb2008/extension/main.h 1.2 + aversive_projects microb2008/extension/multiservo_config.h 1.1 + aversive_projects microb2008/extension/pid_config.h 1.1 aversive_projects microb2008/extension/pwm_config.h 1.2 aversive_projects microb2008/extension/scheduler_config.h 1.3 + aversive_projects microb2008/extension/timer_config.h 1.1 ============================================== aversive_projects/microb2008/extension/.config (1.5 -> 1.6) ============================================== @@ -1,5 +1,5 @@ # -# Automatically generated make config: don't edit +# Automatically generated by make menuconfig: don't edit # # @@ -70,10 +70,6 @@ # # Base modules # - -# -# Enable math library in generation options to see all modules -# # CONFIG_MODULE_CIRBUF is not set # CONFIG_MODULE_CIRBUF_LARGE is not set # CONFIG_MODULE_FIXED_POINT is not set @@ -81,18 +77,14 @@ CONFIG_MODULE_SCHEDULER=y CONFIG_MODULE_SCHEDULER_CREATE_CONFIG=y # CONFIG_MODULE_SCHEDULER_USE_TIMERS is not set -CONFIG_MODULE_SCHEDULER_TIMER0=y -# CONFIG_MODULE_SCHEDULER_MANUAL is not set +# CONFIG_MODULE_SCHEDULER_TIMER0 is not set +CONFIG_MODULE_SCHEDULER_MANUAL=y # CONFIG_MODULE_TIME is not set # CONFIG_MODULE_TIME_CREATE_CONFIG is not set # # Communication modules # - -# -# uart needs circular buffer, mf2 client may need scheduler -# # CONFIG_MODULE_UART is not set # CONFIG_MODULE_UART_CREATE_CONFIG is not set CONFIG_MODULE_I2C=y @@ -108,8 +100,8 @@ # # Hardware modules # -# CONFIG_MODULE_TIMER is not set -# CONFIG_MODULE_TIMER_CREATE_CONFIG is not set +CONFIG_MODULE_TIMER=y +CONFIG_MODULE_TIMER_CREATE_CONFIG=y # CONFIG_MODULE_TIMER_DYNAMIC is not set CONFIG_MODULE_PWM=y CONFIG_MODULE_PWM_CREATE_CONFIG=y @@ -132,8 +124,8 @@ # # CONFIG_MODULE_LCD is not set # CONFIG_MODULE_LCD_CREATE_CONFIG is not set -# CONFIG_MODULE_MULTISERVO is not set -# CONFIG_MODULE_MULTISERVO_CREATE_CONFIG is not set +CONFIG_MODULE_MULTISERVO=y +CONFIG_MODULE_MULTISERVO_CREATE_CONFIG=y # # Brushless motor drivers (you should enable pwm modules to see all) @@ -146,8 +138,8 @@ # # Encoders # -# CONFIG_MODULE_ENCODERS_MICROB is not set -# CONFIG_MODULE_ENCODERS_MICROB_CREATE_CONFIG is not set +CONFIG_MODULE_ENCODERS_MICROB=y +CONFIG_MODULE_ENCODERS_MICROB_CREATE_CONFIG=y # CONFIG_MODULE_ENCODERS_EIRBOT is not set # CONFIG_MODULE_ENCODERS_EIRBOT_CREATE_CONFIG is not set @@ -157,20 +149,16 @@ # CONFIG_MODULE_ROBOT_SYSTEM is not set # CONFIG_MODULE_POSITION_MANAGER is not set # CONFIG_MODULE_TRAJECTORY_MANAGER is not set -# CONFIG_MODULE_BLOCKING_DETECTION_MANAGER is not set +CONFIG_MODULE_BLOCKING_DETECTION_MANAGER=y # CONFIG_MODULE_OBSTACLE_AVOIDANCE is not set # # Control system modules # -# CONFIG_MODULE_CONTROL_SYSTEM_MANAGER is not set - -# -# Filters -# -# CONFIG_MODULE_PID is not set -# CONFIG_MODULE_PID_CREATE_CONFIG is not set -# CONFIG_MODULE_RAMP is not set +CONFIG_MODULE_CONTROL_SYSTEM_MANAGER=y +CONFIG_MODULE_PID=y +CONFIG_MODULE_PID_CREATE_CONFIG=y +CONFIG_MODULE_RAMP=y # CONFIG_MODULE_QUADRAMP is not set # CONFIG_MODULE_QUADRAMP_DERIVATE is not set # CONFIG_MODULE_BIQUAD is not set @@ -178,10 +166,6 @@ # # Crypto modules # - -# -# Crypto modules depend on utils module -# # CONFIG_MODULE_AES is not set # CONFIG_MODULE_AES_CTR is not set # CONFIG_MODULE_MD5 is not set @@ -191,20 +175,12 @@ # # Encodings modules # - -# -# Encoding modules depend on utils module -# # CONFIG_MODULE_BASE64 is not set # CONFIG_MODULE_HAMMING is not set # # Debug modules # - -# -# Debug modules depend on utils module -# # CONFIG_MODULE_DIAGNOSTIC is not set # CONFIG_MODULE_DIAGNOSTIC_CREATE_CONFIG is not set CONFIG_MODULE_ERROR=y =============================================== aversive_projects/microb2008/extension/Makefile (1.2 -> 1.3) =============================================== @@ -16,6 +16,8 @@ # care about how the name is spelled on its command-line. ASRC = +AVRDUDE_DELAY=10 + ######################################## -include .aversive_conf =============================================================== aversive_projects/microb2008/extension/encoders_microb_config.h (1.1) =============================================================== @@ -0,0 +1,45 @@ +/* + * Copyright Droids Corporation, Microb Technology, Eirbot (2005) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Revision : $Id: encoders_microb_config.h,v 1.1 2008-01-09 22:24:12 zer0 Exp $ + * + */ +#ifndef _ENCODERS_MICROB_CONFIG_H_ +#define _ENCODERS_MICROB_CONFIG_H_ + +/** number of the LAST encoders used + 1 */ +#define ENCODERS_MICROB_NUMBER 2 + +#define ENCODERS_MICROB_SEL_PORT PORTD +#define ENCODERS_MICROB_SEL_BIT 2 + +#define ENCODERS_MICROB0_ENABLED +#define ENCODERS_MICROB0_PIN PINA + +#define ENCODERS_MICROB1_ENABLED +#define ENCODERS_MICROB1_PIN PINA +/* +#define ENCODERS_MICROB2_ENABLED +#define ENCODERS_MICROB2_PIN PINC + +#define ENCODERS_MICROB3_ENABLED +#define ENCODERS_MICROB3_PIN PINC +*/ + +// ... until 7 + +#endif ===================================================== aversive_projects/microb2008/extension/i2c_protocol.c (1.5 -> 1.6) ===================================================== @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: i2c_protocol.c,v 1.5 2008-01-07 22:49:06 zer0 Exp $ + * Revision : $Id: i2c_protocol.c,v 1.6 2008-01-09 22:24:12 zer0 Exp $ * */ @@ -26,6 +26,7 @@ #include <i2c.h> #include <pwm.h> +#include <control_system_manager.h> #include "main.h" #include "../common/i2c_commands.h" @@ -42,7 +43,7 @@ /*** LED CONTROL ***/ void i2c_led_control(uint8_t l, uint8_t state) { - switch(l){ + switch(l) { case 5: state? LED5_ON():LED5_OFF(); break; @@ -52,7 +53,50 @@ case 7: state? LED7_ON():LED7_OFF(); break; + default: + break; + } +} +/*** LED CONTROL ***/ +void i2c_control(struct i2c_cmd_extension * cmd) +{ + switch(cmd->cmd) { + case I2C_EXTENSION_COMMAND_HARVEST: + break; + case I2C_EXTENSION_COMMAND_PICKUP: + break; + case I2C_EXTENSION_COMMAND_PREPARE_WHITE: + break; + case I2C_EXTENSION_COMMAND_PREPARE_COLORED: + break; + case I2C_EXTENSION_COMMAND_DROP: + break; + case I2C_EXTENSION_COMMAND_ROLLER_SPEED: + cs_set_consign(&ext.cs_r, cmd->u.s.roller_speed); + break; + case I2C_EXTENSION_COMMAND_ROLLER_ANGLE: + /* multiservo something */ + break; + case I2C_EXTENSION_COMMAND_ROLLER_CS_ON: + ext.flags |= ROLLER_CS_ON; + break; + case I2C_EXTENSION_COMMAND_ROLLER_CS_OFF: + ext.flags &= (~ROLLER_CS_ON); + pwm_set(ROLLER_PWM, 0); + break; + case I2C_EXTENSION_COMMAND_BARREL_POS: + cs_set_consign(&ext.cs_b, cmd->u.barrel_pos); + break; + case I2C_EXTENSION_COMMAND_BARREL_CS_ON: + ext.flags |= BARREL_CS_ON; + break; + case I2C_EXTENSION_COMMAND_BARREL_CS_OFF: + ext.flags &= (~BARREL_CS_ON); + pwm_set(BARREL_PWM, 0); + break; + default: + break; } } @@ -87,16 +131,15 @@ return c; } -static uint8_t val1=0, val2=0, val3=0; - void i2c_send_status(void) { struct i2c_ans_extension_status ans; i2c_flush(); ans.hdr.cmd = I2C_ANS_EXTENSION_STATUS; - ans.state = val1; - ans.white_ball_count = val2; - ans.colored_ball_count = val3; + ans.state = ext.state; + ans.white_ball_count = ext.white_ball_count; + ans.colored_ball_count = ext.colored_ball_count; + ans.roller_speed = ext.roller_speed; /* XXX check return value. To wait is stupid because we are called with irq disabled */ i2c_send(I2C_ADD_MASTER, (uint8_t *) &ans, sizeof(ans), I2C_CTRL_GENERIC); @@ -133,7 +176,7 @@ struct i2c_cmd_extension * cmd = (struct i2c_cmd_extension *) buf; if (size != sizeof (*cmd)) goto error; - /* i2c_control(); */ + i2c_control(cmd); break; } ============================================= aversive_projects/microb2008/extension/main.c (1.8 -> 1.9) ============================================= @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: main.c,v 1.8 2008-01-07 22:49:06 zer0 Exp $ + * Revision : $Id: main.c,v 1.9 2008-01-09 22:24:12 zer0 Exp $ * */ @@ -31,11 +31,17 @@ #include <scheduler.h> #include <i2c.h> #include <pwm.h> +#include <pid.h> +#include <ramp.h> +#include <control_system_manager.h> +#include <timer.h> +#include <encoders_microb.h> #include "main.h" #include "i2c_protocol.h" #include "../common/i2c_commands.h" +struct ext ext; #define DEBUG_LED_BLINK @@ -53,33 +59,127 @@ #endif } +/* called every 5 ms */ +void do_cs(void * dummy) +{ + static int32_t roller_prev_pos = 0; + int32_t roller_pos; + + /* process roller speed */ + roller_pos = encoders_microb_get_value(ROLLER_ENCODER); + ext.roller_speed = roller_prev_pos - roller_pos; /* sign inverted */ + roller_prev_pos = roller_pos; + + if (ext.flags & ROLLER_CS_ON) + cs_manage(&ext.cs_r); + + if (ext.flags & BARREL_CS_ON) + cs_manage(&ext.cs_b); + bd_manage(&ext.bd_b); +} + +void main_timer_interrupt(void) +{ + static uint8_t cpt = 0; + static uint8_t encoder_running = 0; + + cpt++; + + if (encoder_running) + return; + + encoder_running = 1; + sei(); + + encoders_microb_manage(NULL); + encoder_running = 0; + + if ((cpt%4) == 0) + scheduler_interrupt(); +} + +int32_t roller_get_speed(void * dummy) +{ + /* invert sign */ + return -ext.roller_speed; +} + int main(void) { /* i/o */ DDRB = (1<<LED5BIT) | (1<<LED6BIT) | (1<<LED7BIT) ; + memset(&ext, 0, sizeof(struct ext)); + ext.flags = ROLLER_CS_ON | BARREL_CS_ON; - pwm_init(); - - /* scheduler */ - scheduler_init(); - scheduler_add_periodical_event_priority(do_debug, NULL, 100000L/SCHEDULER_UNIT, 100); - - i2c_protocol_init(); - /* i2c */ + i2c_protocol_init(); i2c_init(I2C_MODE_SLAVE, I2C_EXTENSION_ADDR); i2c_register_recv_event(i2c_recvevent); //i2c_register_send_event(i2c_sendevent); //i2c_register_recv_byte_event(i2c_recvbyteevent); + encoders_microb_init(); + + /* Timer */ + timer_init(); + timer0_register_OV_intr(main_timer_interrupt); + pwm_init(); + + /* scheduler */ + scheduler_init(); + scheduler_add_periodical_event_priority(do_debug, NULL, + 100000L/SCHEDULER_UNIT, LED_PRIO); + + scheduler_add_periodical_event_priority(do_cs, NULL, + 5000L / SCHEDULER_UNIT, CS_PRIO); + /* multiservo */ + // multiservo_init(); /* XXX which timer ? */ + + /* CS Roller (speed) */ + pid_init(&ext.pid_r); + pid_set_gains(&ext.pid_r, 500, 5, 0); + pid_set_maximums(&ext.pid_r, 0, 5000, 4095); + pid_set_out_shift(&ext.pid_r, 4); + + cs_init(&ext.cs_r); + cs_set_correct_filter(&ext.cs_r, pid_do_filter, &ext.pid_r); + cs_set_process_in(&ext.cs_r, pwm_set, ROLLER_PWM); + cs_set_process_out(&ext.cs_r, roller_get_speed, NULL); + cs_set_consign(&ext.cs_r, 0); + + /* CS barrel (position) */ + pid_init(&ext.pid_b); + pid_set_gains(&ext.pid_b, 2000, 0, 0); + pid_set_maximums(&ext.pid_b, 0, 100000, 4095); + pid_set_out_shift(&ext.pid_b, 10); + pid_set_derivate_filter(&ext.pid_b, 4); + + ramp_init(&ext.r_b); + ramp_set_vars(&ext.r_b, 200, 200); /* set speed */ + + cs_init(&ext.cs_b); + cs_set_consign_filter(&ext.cs_b, ramp_do_filter, &ext.r_b); + cs_set_correct_filter(&ext.cs_b, pid_do_filter, &ext.pid_b); + cs_set_process_in(&ext.cs_b, pwm_set, BARREL_PWM); + cs_set_process_out(&ext.cs_b, encoders_microb_get_value, BARREL_ENCODER); + cs_set_consign(&ext.cs_b, 0); + + bd_init(&ext.bd_b, &ext.cs_b); + bd_set_thresholds(&ext.bd_b, 300, 300, 20); + /* debug via i2c (um zu gut zu machen) */ fdevopen(debug_send, NULL); sei(); while(1) { - wait_ms(1000); - printf("ext"); + if (bd_get(&ext.bd_b)) { + cs_set_consign(&ext.cs_b, encoders_microb_get_value(BARREL_ENCODER)); + printf("B"); + wait_ms(300); + } +/* wait_ms(500); */ +/* printf("%ld", encoders_microb_get_value(BARREL_ENCODER)); */ } while(1); ============================================= aversive_projects/microb2008/extension/main.h (1.1 -> 1.2) ============================================= @@ -15,14 +15,54 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: main.h,v 1.1 2007-06-28 18:14:37 zer0 Exp $ + * Revision : $Id: main.h,v 1.2 2008-01-09 22:24:12 zer0 Exp $ * */ -/********************** LEDS */ #ifndef _MAIN_H_ #define _MAIN_H_ +#include <control_system_manager.h> +#include <blocking_detection_manager.h> +#include <pid.h> +#include <ramp.h> + +struct ext { + /* roller */ + struct cs cs_r; + struct pid_filter pid_r; + + /* barrel */ + struct cs cs_b; + struct pid_filter pid_b; + struct ramp_filter r_b; + struct blocking_detection bd_b; + + uint8_t state; + uint8_t flags; + uint8_t white_ball_count; + uint8_t colored_ball_count; + int16_t roller_speed; + +}; + +extern struct ext ext; + +#define BARREL_PWM ((void *)PWM1B_NUM) +#define BARREL_ENCODER ((void *) 0) + +#define ROLLER_PWM ((void *)PWM1A_NUM) +#define ROLLER_ENCODER ((void *) 1) + +/* event priorities (from highest to lowest) */ +#define LED_PRIO 170 +#define CS_PRIO 150 + +#define ROLLER_CS_ON 1 +#define BARREL_CS_ON 2 + +/********************** LEDS */ + #define LED5BIT 2 #define LED6BIT 3 #define LED7BIT 4 ========================================================== aversive_projects/microb2008/extension/multiservo_config.h (1.1) ========================================================== @@ -0,0 +1,59 @@ +/* + * Copyright Droids Corporation, Microb Technology, Eirbot (2006) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Revision : $Id: multiservo_config.h,v 1.1 2008-01-09 22:24:12 zer0 Exp $ + * + */ + + +#ifndef _MULTISERVO_CONFIG_H_ +#define _MULTISERVO_CONFIG_H_ + +/** we need one timer, can be 0, 1, 2, 3 (depending on arch) */ +#define MULTISERVO_TIMER 1 + +/* You should specify the config for prescaler + * It is in TCCRnB for 16 bits timer or in TCCRn for + * 8 bits timer. See the doc of your AVR device. + * This is not automatic because it would be too complicated. + * + * Example (for timer 3, prescaler 1) : + * + * #define MULTISERVO_TIMER_PRESCALER 1 + * #define MULTISERVO_TIMER_PRESCALER_CONFIG (1 << CS30) + * + * Another example (for timer 2, prescaler 32) : + * + * #define MULTISERVO_TIMER_PRESCALER 128 + * #define MULTISERVO_TIMER_PRESCALER_CONFIG ((1 << CS22) | (1 << CS20)) + * + * XXX : currently, the user has to choose a good prescaler + * value. A good prescaler value is the more precise value + * (the highest) that can count during 2 ms. + */ +/* ok for atm 128 */ +/* #define MULTISERVO_TIMER_PRESCALER 256 */ +/* #define MULTISERVO_TIMER_PRESCALER_CONFIG (1 << CS22) */ + +#define MULTISERVO_TIMER_PRESCALER 256 +#define MULTISERVO_TIMER_PRESCALER_CONFIG (1 << CS22) +/* #define MULTISERVO_TIMER_PRESCALER 1 */ +/* #define MULTISERVO_TIMER_PRESCALER_CONFIG (1 << CS10) */ + +#define MULTISERVO_NB_MAX 4 + +#endif =================================================== aversive_projects/microb2008/extension/pid_config.h (1.1) =================================================== @@ -0,0 +1,30 @@ +/* + * Copyright Droids Corporation, Microb Technology, Eirbot (2005) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + * + */ + +#ifndef PID_CONFIG_H +#define PID_CONFIG_H + +/** the derivate term can be filtered to remove the noise. This value + * is the maxium sample count to keep in memory to do this + * filtering. For an instance of pid, this count is defined o*/ +#define PID_DERIVATE_FILTER_MAX_SIZE 4 + +#endif =================================================== aversive_projects/microb2008/extension/pwm_config.h (1.1 -> 1.2) =================================================== @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: pwm_config.h,v 1.1 2007-12-31 16:23:48 zer0 Exp $ + * Revision : $Id: pwm_config.h,v 1.2 2008-01-09 22:24:12 zer0 Exp $ * */ @@ -43,14 +43,14 @@ #define PWM_SIGNIFICANT_BITS 12 #define TIMER1_MODE TIMER_16_MODE_PWM_10 -#define TIMER1_PRESCALE TIMER1_PRESCALER_DIV_8 +#define TIMER1_PRESCALE TIMER1_PRESCALER_DIV_1 #define PWM1A_MODE (PWM_SIGNED) #define PWM1A_SIGN_PORT PORTB #define PWM1A_SIGN_BIT 1 -#define PWM1B_MODE (PWM_SIGNED) +#define PWM1B_MODE (PWM_SIGNED|PWM_SIGN_INVERTED) #define PWM1B_SIGN_PORT PORTB #define PWM1B_SIGN_BIT 0 ========================================================= aversive_projects/microb2008/extension/scheduler_config.h (1.2 -> 1.3) ========================================================= @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: scheduler_config.h,v 1.2 2007-12-31 16:23:48 zer0 Exp $ + * Revision : $Id: scheduler_config.h,v 1.3 2008-01-09 22:24:12 zer0 Exp $ * */ @@ -27,12 +27,8 @@ /** maximum number of allocated events */ #define SCHEDULER_NB_MAX_EVENT 5 - -/* The 2 values below MUST be coherent: - * if SCHEDULER_CK = TIMER0_PRESCALER_DIV_x, then - * you must have SCHEDULER_CLOCK_PRESCALER = x too !!! */ -#define SCHEDULER_CK TIMER0_PRESCALER_DIV_8 -#define SCHEDULER_CLOCK_PRESCALER 8 +#define SCHEDULER_UNIT_FLOAT 512.0 +#define SCHEDULER_UNIT 512L /** number of allowed imbricated scheduler interrupts. The maximum * should be SCHEDULER_NB_MAX_EVENT since we never need to imbricate ===================================================== aversive_projects/microb2008/extension/timer_config.h (1.1) ===================================================== @@ -0,0 +1,23 @@ +/* + * Copyright Droids Corporation, Microb Technology, Eirbot (2006) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Revision : $Id: timer_config.h,v 1.1 2008-01-09 22:24:12 zer0 Exp $ + * + */ + +#define TIMER0_ENABLED +#define TIMER0_PRESCALER_DIV 8 Commit from zer0 (2008-01-09 23:24 CET) ================ add barrel and roller handling aversive_projects microb2008/common/i2c_commands.h 1.5 aversive_projects microb2008/main/commands.c 1.10 aversive_projects microb2008/main/i2c_protocol.c 1.8 aversive_projects microb2008/main/i2c_protocol.h 1.5 aversive_projects microb2008/main/main.c 1.16 aversive_projects microb2008/main/main.h 1.9 ================================================== aversive_projects/microb2008/common/i2c_commands.h (1.4 -> 1.5) ================================================== @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: i2c_commands.h,v 1.4 2008-01-07 22:49:06 zer0 Exp $ + * Revision : $Id: i2c_commands.h,v 1.5 2008-01-09 22:24:45 zer0 Exp $ * */ @@ -55,12 +55,24 @@ #define I2C_EXTENSION_COMMAND_PREPARE_WHITE 2 /* prepare a white ball drop and set roller */ #define I2C_EXTENSION_COMMAND_PREPARE_COLORED 3 /* prepare a colored ball drop and set roller */ #define I2C_EXTENSION_COMMAND_DROP 4 /* drop ball */ +#define I2C_EXTENSION_COMMAND_ROLLER_SPEED 5 /* set roller_speed only */ +#define I2C_EXTENSION_COMMAND_ROLLER_ANGLE 6 /* set roller_angle only */ +#define I2C_EXTENSION_COMMAND_ROLLER_CS_ON 7 /* enable roller cs */ +#define I2C_EXTENSION_COMMAND_ROLLER_CS_OFF 8 /* disable roller cs */ +#define I2C_EXTENSION_COMMAND_BARREL_POS 9 /* set barrel position */ +#define I2C_EXTENSION_COMMAND_BARREL_CS_ON 10 /* enable barrel cs */ +#define I2C_EXTENSION_COMMAND_BARREL_CS_OFF 11 /* disable barrel cs */ struct i2c_cmd_extension { struct i2c_cmd_hdr hdr; uint8_t cmd; - uint8_t roller_speed; - uint8_t roller_angle; + union { + struct { + int16_t roller_speed; + uint8_t roller_angle; + } s; + int32_t barrel_pos; + } u; }; /****/ @@ -113,6 +125,7 @@ uint8_t state; uint8_t white_ball_count; uint8_t colored_ball_count; + int16_t roller_speed; }; ============================================ aversive_projects/microb2008/main/commands.c (1.9 -> 1.10) ============================================ @@ -1804,6 +1804,7 @@ printf_P(PSTR("state=%x white=%d colored=%d\n"), robot.extension_state, robot.white_ball_count, robot.colored_ball_count); + printf_P(PSTR("current roller speed=%d\n"), robot.roller_speed); } prog_char str_extension_arg0[] = "extension"; @@ -1823,8 +1824,135 @@ }, }; +/**********************************************************/ +/* Roller */ + + +/* this structure is filled when cmd_roller is parsed successfully */ +struct cmd_roller_result { + fixed_string_t arg0; + fixed_string_t arg1; + int16_t arg2; +}; + +/* function called when cmd_roller is parsed successfully */ +static void cmd_roller_parsed(void * parsed_result, void * data) +{ + struct cmd_roller_result *res = (struct cmd_roller_result *) parsed_result; + + if (!strcmp_P(res->arg1, PSTR("speed"))) { + i2c_roller_speed(res->arg2); + } + else if (!strcmp_P(res->arg1, PSTR("angle"))) { + i2c_roller_angle(res->arg2); + } + else if (!strcmp_P(res->arg1, PSTR("cs_on"))) { + i2c_roller_cs_on(); + } + else if (!strcmp_P(res->arg1, PSTR("cs_off"))) { + i2c_roller_cs_off(); + } +} + +prog_char str_roller_arg0[] = "roller"; +parse_pgm_token_string_t cmd_roller_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_roller_result, arg0, str_roller_arg0); +prog_char str_roller_arg1[] = "speed#angle"; +parse_pgm_token_string_t cmd_roller_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_roller_result, arg1, str_roller_arg1); +parse_pgm_token_num_t cmd_roller_arg2 = TOKEN_NUM_INITIALIZER(struct cmd_log_result, arg2, INT16); + + +prog_char help_roller[] = "Set roller speed"; +parse_pgm_inst_t cmd_roller = { + .f = cmd_roller_parsed, /* function to call */ + .data = NULL, /* 2nd arg of func */ + .help_str = help_roller, + .tokens = { /* token list, NULL terminated */ + (prog_void *)&cmd_roller_arg0, + (prog_void *)&cmd_roller_arg1, + (prog_void *)&cmd_roller_arg2, + NULL, + }, +}; + +prog_char str_roller_arg1_cs[] = "cs_on#cs_off"; +parse_pgm_token_string_t cmd_roller_arg1_cs = TOKEN_STRING_INITIALIZER(struct cmd_roller_result, arg1, str_roller_arg1_cs); + + +prog_char help_roller_cs[] = "Enable/disable roller cs"; +parse_pgm_inst_t cmd_roller_cs = { + .f = cmd_roller_parsed, /* function to call */ + .data = NULL, /* 2nd arg of func */ + .help_str = help_roller_cs, + .tokens = { /* token list, NULL terminated */ + (prog_void *)&cmd_roller_arg0, + (prog_void *)&cmd_roller_arg1_cs, + NULL, + }, +}; +/**********************************************************/ +/* Barrel */ + + +/* this structure is filled when cmd_barrel is parsed successfully */ +struct cmd_barrel_result { + fixed_string_t arg0; + fixed_string_t arg1; + int32_t arg2; +}; + +/* function called when cmd_barrel is parsed successfully */ +static void cmd_barrel_parsed(void * parsed_result, void * data) +{ + struct cmd_barrel_result *res = (struct cmd_barrel_result *) parsed_result; + + if (!strcmp_P(res->arg1, PSTR("pos"))) { + i2c_barrel_pos(res->arg2); + } + else if (!strcmp_P(res->arg1, PSTR("cs_on"))) { + i2c_barrel_cs_on(); + } + else if (!strcmp_P(res->arg1, PSTR("cs_off"))) { + i2c_barrel_cs_off(); + } +} + +prog_char str_barrel_arg0[] = "barrel"; +parse_pgm_token_string_t cmd_barrel_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_barrel_result, arg0, str_barrel_arg0); +prog_char str_barrel_arg1[] = "pos"; +parse_pgm_token_string_t cmd_barrel_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_barrel_result, arg1, str_barrel_arg1); +parse_pgm_token_num_t cmd_barrel_arg2 = TOKEN_NUM_INITIALIZER(struct cmd_log_result, arg2, INT32); + + +prog_char help_barrel[] = "Set barrel position"; +parse_pgm_inst_t cmd_barrel = { + .f = cmd_barrel_parsed, /* function to call */ + .data = NULL, /* 2nd arg of func */ + .help_str = help_barrel, + .tokens = { /* token list, NULL terminated */ + (prog_void *)&cmd_barrel_arg0, + (prog_void *)&cmd_barrel_arg1, + (prog_void *)&cmd_barrel_arg2, + NULL, + }, +}; + +prog_char str_barrel_arg1_cs[] = "cs_on#cs_off"; +parse_pgm_token_string_t cmd_barrel_arg1_cs = TOKEN_STRING_INITIALIZER(struct cmd_barrel_result, arg1, str_barrel_arg1_cs); + + +prog_char help_barrel_cs[] = "Enable/disable barrel cs"; +parse_pgm_inst_t cmd_barrel_cs = { + .f = cmd_barrel_parsed, /* function to call */ + .data = NULL, /* 2nd arg of func */ + .help_str = help_barrel_cs, + .tokens = { /* token list, NULL terminated */ + (prog_void *)&cmd_barrel_arg0, + (prog_void *)&cmd_barrel_arg1_cs, + NULL, + }, +}; @@ -1871,6 +1999,10 @@ (parse_pgm_inst_t *)&cmd_trajectory_show, (parse_pgm_inst_t *)&cmd_opponent, (parse_pgm_inst_t *)&cmd_opponent_set, - (parse_pgm_inst_t *)&cmd_extension, + (parse_pgm_inst_t *)&cmd_extension, + (parse_pgm_inst_t *)&cmd_roller, + (parse_pgm_inst_t *)&cmd_roller_cs, + (parse_pgm_inst_t *)&cmd_barrel, + (parse_pgm_inst_t *)&cmd_barrel_cs, NULL, }; ================================================ aversive_projects/microb2008/main/i2c_protocol.c (1.7 -> 1.8) ================================================ @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: i2c_protocol.c,v 1.7 2008-01-07 22:49:06 zer0 Exp $ + * Revision : $Id: i2c_protocol.c,v 1.8 2008-01-09 22:24:45 zer0 Exp $ * */ @@ -156,6 +156,7 @@ robot.extension_state = ans->state; robot.white_ball_count = ans->white_ball_count; robot.colored_ball_count = ans->colored_ball_count; + robot.roller_speed = ans->roller_speed; break; } @@ -243,23 +244,82 @@ i2c_send_command((uint8_t*)&buf, sizeof(buf)); } -void i2c_prepare_white(uint8_t roller_speed, uint8_t roller_angle) +void i2c_prepare_white(int16_t roller_speed, uint8_t roller_angle) { struct i2c_cmd_extension buf; buf.hdr.cmd = I2C_CMD_EXTENSION_CONTROL; buf.cmd = I2C_EXTENSION_COMMAND_PREPARE_WHITE; - buf.roller_speed = roller_speed; - buf.roller_angle = roller_angle; + buf.u.s.roller_speed = roller_speed; + buf.u.s.roller_angle = roller_angle; i2c_send_command((uint8_t*)&buf, sizeof(buf)); } -void i2c_prepare_colored(uint8_t roller_speed, uint8_t roller_angle) +void i2c_prepare_colored(int16_t roller_speed, uint8_t roller_angle) { struct i2c_cmd_extension buf; buf.hdr.cmd = I2C_CMD_EXTENSION_CONTROL; buf.cmd = I2C_EXTENSION_COMMAND_PREPARE_COLORED; - buf.roller_speed = roller_speed; - buf.roller_angle = roller_angle; + buf.u.s.roller_speed = roller_speed; + buf.u.s.roller_angle = roller_angle; + i2c_send_command((uint8_t*)&buf, sizeof(buf)); +} + +void i2c_roller_speed(int16_t roller_speed) +{ + struct i2c_cmd_extension buf; + buf.hdr.cmd = I2C_CMD_EXTENSION_CONTROL; + buf.cmd = I2C_EXTENSION_COMMAND_ROLLER_SPEED; + buf.u.s.roller_speed = roller_speed; + i2c_send_command((uint8_t*)&buf, sizeof(buf)); +} + +void i2c_roller_angle(uint8_t roller_angle) +{ + struct i2c_cmd_extension buf; + buf.hdr.cmd = I2C_CMD_EXTENSION_CONTROL; + buf.cmd = I2C_EXTENSION_COMMAND_ROLLER_ANGLE; + buf.u.s.roller_angle = roller_angle; + i2c_send_command((uint8_t*)&buf, sizeof(buf)); +} + +void i2c_roller_cs_on(void) +{ + struct i2c_cmd_extension buf; + buf.hdr.cmd = I2C_CMD_EXTENSION_CONTROL; + buf.cmd = I2C_EXTENSION_COMMAND_ROLLER_CS_ON; + i2c_send_command((uint8_t*)&buf, sizeof(buf)); +} + +void i2c_roller_cs_off(void) +{ + struct i2c_cmd_extension buf; + buf.hdr.cmd = I2C_CMD_EXTENSION_CONTROL; + buf.cmd = I2C_EXTENSION_COMMAND_ROLLER_CS_OFF; + i2c_send_command((uint8_t*)&buf, sizeof(buf)); +} + +void i2c_barrel_pos(int32_t barrel_pos) +{ + struct i2c_cmd_extension buf; + buf.hdr.cmd = I2C_CMD_EXTENSION_CONTROL; + buf.cmd = I2C_EXTENSION_COMMAND_BARREL_POS; + buf.u.barrel_pos = barrel_pos; + i2c_send_command((uint8_t*)&buf, sizeof(buf)); +} + +void i2c_barrel_cs_on(void) +{ + struct i2c_cmd_extension buf; + buf.hdr.cmd = I2C_CMD_EXTENSION_CONTROL; + buf.cmd = I2C_EXTENSION_COMMAND_BARREL_CS_ON; + i2c_send_command((uint8_t*)&buf, sizeof(buf)); +} + +void i2c_barrel_cs_off(void) +{ + struct i2c_cmd_extension buf; + buf.hdr.cmd = I2C_CMD_EXTENSION_CONTROL; + buf.cmd = I2C_EXTENSION_COMMAND_BARREL_CS_OFF; i2c_send_command((uint8_t*)&buf, sizeof(buf)); } ================================================ aversive_projects/microb2008/main/i2c_protocol.h (1.4 -> 1.5) ================================================ @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: i2c_protocol.h,v 1.4 2008-01-07 22:49:06 zer0 Exp $ + * Revision : $Id: i2c_protocol.h,v 1.5 2008-01-09 22:24:45 zer0 Exp $ * */ @@ -44,8 +44,15 @@ void i2c_harvest(void); void i2c_pickup(void); void i2c_drop(void); -void i2c_prepare_white(uint8_t roller_speed, uint8_t roller_angle); -void i2c_prepare_colored(uint8_t roller_speed, uint8_t roller_angle); +void i2c_prepare_white(int16_t roller_speed, uint8_t roller_angle); +void i2c_prepare_colored(int16_t roller_speed, uint8_t roller_angle); +void i2c_roller_speed(int16_t roller_speed); +void i2c_roller_angle(uint8_t roller_angle); +void i2c_roller_cs_on(void); +void i2c_roller_cs_off(void); +void i2c_barrel_pos(int32_t barrel_pos); +void i2c_barrel_cs_on(void); +void i2c_barrel_cs_off(void); int8_t i2c_req_extension_status(void); #endif ======================================== aversive_projects/microb2008/main/main.c (1.15 -> 1.16) ======================================== @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: main.c,v 1.15 2008-01-07 22:49:06 zer0 Exp $ + * Revision : $Id: main.c,v 1.16 2008-01-09 22:24:45 zer0 Exp $ * */ @@ -84,7 +84,8 @@ } /* called every 5 ms */ -void do_cs(void * dummy) { +void do_cs(void * dummy) +{ static uint8_t cpt = 0; uint8_t second; @@ -167,7 +168,7 @@ cpt++; - /* BAAAAd */ + /* log ? */ if (encoder_running) return; ======================================== aversive_projects/microb2008/main/main.h (1.8 -> 1.9) ======================================== @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: main.h,v 1.8 2008-01-05 23:36:19 zer0 Exp $ + * Revision : $Id: main.h,v 1.9 2008-01-09 22:24:45 zer0 Exp $ * */ @@ -70,7 +70,6 @@ #define E_USER_SENSOR 197 /* event priorities (from highest to lowest) */ -#define ENCODERS_PRIO 200 #define LED_PRIO 170 #define TIME_PRIO 160 #define CS_PRIO 150 @@ -105,6 +104,7 @@ uint8_t extension_state; uint8_t white_ball_count; uint8_t colored_ball_count; + int16_t roller_speed; uint8_t logs[NB_LOGS]; uint8_t log_level; Commit from zer0 on branch b_zer0 (2008-01-09 23:26 CET) ================================= remove bad dep aversive config/config.in 1.42.4.18 ========================= aversive/config/config.in (1.42.4.17 -> 1.42.4.18) ========================= @@ -330,11 +330,10 @@ $CONFIG_MODULE_FIXED_POINT #### BLOCKING DETECTION MANAGER -dep_bool 'Blocking detection manager' CONFIG_MODULE_BLOCKING_DETECTION_MANAGER \ - $CONFIG_MODULE_ROBOT_SYSTEM +bool 'Blocking detection manager' CONFIG_MODULE_BLOCKING_DETECTION_MANAGER #### OBSTACLE AVOIDANCE -dep_bool 'Obstacle Avoidance' CONFIG_MODULE_OBSTACLE_AVOIDANCE +bool 'Obstacle Avoidance' CONFIG_MODULE_OBSTACLE_AVOIDANCE endmenu # (robot) Commit from zer0 on branch b_zer0 (2008-01-09 23:26 CET) ================================= rename delay aversive mk/aversive_project.mk 1.32.4.11 =============================== aversive/mk/aversive_project.mk (1.32.4.10 -> 1.32.4.11) =============================== @@ -113,8 +113,8 @@ AVRDUDE_FLAGS = -e -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -q -ifneq ($(DELAY),) -AVRDUDE_FLAGS += -i $(DELAY) +ifneq ($(AVRDUDE_DELAY),) +AVRDUDE_FLAGS += -i $(AVRDUDE_DELAY) endif export AVRDUDE_FLAGS Commit from zer0 on branch b_zer0 (2008-01-09 23:27 CET) ================================= re-indent aversive modules/devices/control_system/control_system_manager/control_system_manager.h 1.7.4.4 aversive modules/devices/control_system/filters/ramp/ramp.h 1.4.4.2 ======================================================================================= aversive/modules/devices/control_system/control_system_manager/control_system_manager.h (1.7.4.3 -> 1.7.4.4) ======================================================================================= @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: control_system_manager.h,v 1.7.4.3 2007-12-31 16:25:00 zer0 Exp $ + * Revision : $Id: control_system_manager.h,v 1.7.4.4 2008-01-09 22:27:01 zer0 Exp $ * */ @@ -114,22 +114,22 @@ void cs_manage(void * cs); /** Return the last process out send to process */ -int32_t cs_get_out( struct cs* cs); +int32_t cs_get_out(struct cs* cs); /** Return the last calculated error */ -int32_t cs_get_error( struct cs* cs); +int32_t cs_get_error(struct cs* cs); /** Return the current consign */ -int32_t cs_get_consign( struct cs* cs); +int32_t cs_get_consign(struct cs* cs); /** Return the current consign, after filter */ -int32_t cs_get_filtered_consign( struct cs* cs); +int32_t cs_get_filtered_consign(struct cs* cs); /** Return the last feedback value, after filter */ -int32_t cs_get_filtered_feedback( struct cs* cs); +int32_t cs_get_filtered_feedback(struct cs* cs); /** Change the consign without calculating control system */ -void cs_set_consign( struct cs* cs, int32_t v); +void cs_set_consign(struct cs* cs, int32_t v); #endif /* #ifndef _CONTROL_SYSTEM_MANAGER_ */ =========================================================== aversive/modules/devices/control_system/filters/ramp/ramp.h (1.4.4.1 -> 1.4.4.2) =========================================================== @@ -37,9 +37,9 @@ /** \brief Definition of structur ramp_filter */ struct ramp_filter { - uint32_t var_neg; /**Authorized negative variation*/ - uint32_t var_pos; /**Authorized positive variation*/ - int32_t prev_out; /**Previous value calculated*/ + uint32_t var_neg; /**Authorized negative variation*/ + uint32_t var_pos; /**Authorized positive variation*/ + int32_t prev_out; /**Previous value calculated*/ }; Commit from zer0 on branch b_zer0 (2008-01-09 23:27 CET) ================================= no need of f64.h aversive modules/devices/encoders/encoders_microb/encoders_microb.c 1.6.4.3 =================================================================== aversive/modules/devices/encoders/encoders_microb/encoders_microb.c (1.6.4.2 -> 1.6.4.3) =================================================================== @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: encoders_microb.c,v 1.6.4.2 2007-05-23 17:18:13 zer0 Exp $ + * Revision : $Id: encoders_microb.c,v 1.6.4.3 2008-01-09 22:27:19 zer0 Exp $ * */ @@ -57,7 +57,6 @@ #include <aversive.h> #include <aversive/wait.h> -#include <f64.h> #include <encoders_microb.h> #include <encoders_microb_config.h> Commit from zer0 on branch b_zer0 (2008-01-09 23:27 CET) ================================= add comment aversive modules/devices/robot/blocking_detection_manager/blocking_detection_manager.h 1.1.2.2 ====================================================================================== aversive/modules/devices/robot/blocking_detection_manager/blocking_detection_manager.h (1.1.2.1 -> 1.1.2.2) ====================================================================================== @@ -15,16 +15,19 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Revision : $Id: blocking_detection_manager.h,v 1.1.2.1 2007-12-31 16:25:00 zer0 Exp $ + * Revision : $Id: blocking_detection_manager.h,v 1.1.2.2 2008-01-09 22:27:45 zer0 Exp $ * * Olivier MATZ <[EMAIL PROTECTED]> */ /* blocking detection manager */ -#include <robot_system.h> #include <control_system_manager.h> +/* detect blocking : if the speed is below a threshold and the error + * is below another threshold during n tests, trigger the blocking + * detection. */ + struct blocking_detection { struct cs *cs; uint32_t speed_thres; _______________________________________________ Avr-list mailing list Avr-list@droids-corp.org CVSWEB : http://cvsweb.droids-corp.org/cgi-bin/viewcvs.cgi/aversive WIKI : http://wiki.droids-corp.org/index.php/Aversive DOXYGEN : http://zer0.droids-corp.org/doxygen_aversive/html/ BUGZILLA : http://bugzilla.droids-corp.org COMMIT LOGS : http://zer0.droids-corp.org/aversive_commitlog