Je disais donc...

> Bref, assez de blabla, voici le patch. (en fichier attaché).


   Simon
diff -uNr -x .svn -x '*.o' ../../orig/aversive/include/aversive/irq_lock.h 
aversive/include/aversive/irq_lock.h
--- ../../orig/aversive/include/aversive/irq_lock.h     2007-05-23 
19:18:09.000000000 +0200
+++ aversive/include/aversive/irq_lock.h        2009-07-03 20:48:29.000000000 
+0200
@@ -40,6 +40,22 @@
 #ifndef _AVERSIVE_IRQ_LOCK_H_
 #define _AVERSIVE_IRQ_LOCK_H_
 
+#ifdef DSPIC
+#include "p33fxxxx.h"
+#define GLOBAL_IRQ_ARE_MASKED() (!(SRbits.IPL==7))
+
+#define IRQ_LOCK(flags) do {         \
+  flags = SRbits.IPL ;               \
+  cli();                             \
+  } while(0)
+
+#define IRQ_UNLOCK(flags) do {       \
+  SRbits.IPL = flags;                \
+  } while ( 0 )
+
+#else
+
+
 #ifdef HOST_VERSION
 
 /* we must use 'flags' to avoid a warning */
@@ -62,4 +78,5 @@
 
 #endif /* ! HOST_VERSION */
 
+#endif /* ! DSPIC */
 #endif /* _AVERSIVE_IRQ_LOCK_H_ */
diff -uNr -x .svn -x '*.o' ../../orig/aversive/include/aversive/parts.h 
aversive/include/aversive/parts.h
--- ../../orig/aversive/include/aversive/parts.h        2009-01-23 
23:53:08.000000000 +0100
+++ aversive/include/aversive/parts.h   2009-07-03 20:48:29.000000000 +0200
@@ -269,7 +269,9 @@
 #elif defined (__AVR_ATxmega64A3__)
 #include <aversive/parts/ATxmega64A3.h>
 #else
+#ifndef DSPIC
 #error "This arch is not implemented yet"
 #endif
+#endif
 
 #endif /* _AVERSIVE_PARTS_H_ */
diff -uNr -x .svn -x '*.o' ../../orig/aversive/include/aversive.h 
aversive/include/aversive.h
--- ../../orig/aversive/include/aversive.h      2009-05-18 14:19:51.000000000 
+0200
+++ aversive/include/aversive.h 2009-07-03 20:48:29.000000000 +0200
@@ -29,10 +29,14 @@
 #define _AVERSIVE_H_
 
 #include <autoconf.h>
+#include <math.h>
 
 #ifndef HOST_VERSION
-#include <avr/interrupt.h>
-#include <avr/io.h>
+#  ifndef DSPIC
+#    define AVR
+#    include <avr/interrupt.h>
+#    include <avr/io.h>
+#  endif
 #endif
 
 #include <aversive/types.h>
@@ -44,19 +48,27 @@
 #define __AVR_LIBC_VERSION__ 0UL 
 #endif
 
-#ifndef HOST_VERSION
+#ifdef AVR
 #if __AVR_LIBC_VERSION__ < 10403UL
 #include <avr/signal.h>
 #endif
 #endif
 
-#define F_CPU ((unsigned long)CONFIG_QUARTZ)
+#ifdef DSPIC
+#  define F_CPU ((CONFIG_QUARTZ)/2) /* Do NOT make it unsigned, it breaks 
S_MAX(). */
+#  define FCY F_CPU
+#else
+#  define F_CPU ((unsigned long)CONFIG_QUARTZ)
+#endif
 
 #define Hz  1l
 #define KHz 1000l
 #define MHz 1000000l
 
 
+#ifndef M_PI
+#  define M_PI 3.141592653589
+#endif
 
 /*
  *  a few "mathematical" macros : maximums and minimums
@@ -193,7 +205,7 @@
 
 /* a few asm utilities */
 
-#ifndef HOST_VERSION
+#ifdef AVR
 #ifndef nop
 #define nop() __asm__ __volatile__ ("NOP\n") /** nop instruction, 1 CPU cycle 
consumed */
 #endif
@@ -215,14 +227,21 @@
   __asm__ __volatile__ ("ijmp\n");  \
 } while(0)
 #endif
+#endif /* AVR */
 
-#else /* HOST_VERSION */
+#ifdef HOST_VERSION
 #define nop() do {} while(0)
 #define nothing() do {} while(0)
 #define cli() do {} while(0)
 #define sei() do {} while(0)
 #endif /* HOST_VERSION */
 
+#ifdef DSPIC
+#  define nop() do {__asm__ volatile ("nop");} while(0)
+#  define nothing() do {} while(0)
+#  define cli() do {SRbits.IPL=7;} while(0)
+#  define sei() do {SRbits.IPL=0;} while(0)
+#endif /* DSPIC */
 /**
  *   little bit toggeling macro 
  *  
diff -uNr -x .svn -x '*.o' ../../orig/aversive/include/dspic/inttypes.h 
aversive/include/dspic/inttypes.h
--- ../../orig/aversive/include/dspic/inttypes.h        1970-01-01 
01:00:00.000000000 +0100
+++ aversive/include/dspic/inttypes.h   2009-07-02 18:52:14.000000000 +0200
@@ -0,0 +1,13 @@
+#ifndef DSPIC_INTTYPES_H
+#define DSPIC_INTTYPES_H
+
+typedef signed char int8_t;
+typedef unsigned char uint8_t;
+typedef signed int int16_t;
+typedef unsigned int uint16_t;
+typedef signed long int int32_t;
+typedef unsigned long int uint32_t;
+typedef signed long long int64_t;
+typedef unsigned long long uint64_t;
+
+#endif
diff -uNr -x .svn -x '*.o' ../../orig/aversive/include/dspic/stdint.h 
aversive/include/dspic/stdint.h
--- ../../orig/aversive/include/dspic/stdint.h  1970-01-01 01:00:00.000000000 
+0100
+++ aversive/include/dspic/stdint.h     2009-07-03 20:48:29.000000000 +0200
@@ -0,0 +1,4 @@
+#ifndef DSPIC_STDINT_H
+#define DSPIC_STDINT_H
+
+#endif
diff -uNr -x .svn -x '*.o' 
../../orig/aversive/modules/base/scheduler/scheduler.c 
aversive/modules/base/scheduler/scheduler.c
--- ../../orig/aversive/modules/base/scheduler/scheduler.c      2009-01-29 
00:26:01.000000000 +0100
+++ aversive/modules/base/scheduler/scheduler.c 2009-07-03 20:48:30.000000000 
+0200
@@ -21,15 +21,15 @@
 
 #include <string.h>
 
-#include <aversive/parts.h>
 #include <aversive.h>
+#include <aversive/parts.h>
 
 #include <scheduler.h>
 #include <scheduler_private.h>
 #include <scheduler_config.h>
 
 
-/* this file is compiled for AVR version only */
+/* this file is compiled for AVR/DSPIC versions only */
 
 /** declared in scheduler_host.c in case of host version */
 struct event_t g_tab_event[SCHEDULER_NB_MAX_EVENT];
@@ -39,6 +39,18 @@
 {
        memset(g_tab_event, 0, sizeof(g_tab_event));
 
+
+#ifdef DSPIC
+       /* Scheduler uses timer1 on dspic33 */
+       T1CON = 0;              // Timer reset
+       IFS0bits.T1IF = 0;      // Reset Timer1 interrupt flag
+       IPC0bits.T1IP = 4;      // Timer1 Interrupt priority level=4
+       IEC0bits.T1IE = 1;      // Enable Timer1 interrupt
+       TMR1=  0x0000;          
+       PR1 = FCY / SCHEDULER_UNIT;
+       T1CONbits.TON = 1;      // Enable Timer1 and start the counter
+#endif
+
 #ifdef CONFIG_MODULE_SCHEDULER_USE_TIMERS
        SCHEDULER_TIMER_REGISTER();
 #endif
@@ -59,3 +71,17 @@
        scheduler_interrupt();
 }
 #endif /* CONFIG_MODULE_SCHEDULER_USE_TIMERS */
+
+
+#ifdef DSPIC
+/* the ISR name is chosen from the device linker script */
+void __attribute__((__interrupt__, no_auto_psv)) _T1Interrupt(void)
+{
+    // Interrupt Service Routine code goes here */
+    IFS0bits.T1IF=0;
+    
+    scheduler_interrupt();
+    return;
+}
+
+#endif
diff -uNr -x .svn -x '*.o' 
../../orig/aversive/modules/devices/encoders/encoders_igrebot/config/encoders_igrebot_config.h
 
aversive/modules/devices/encoders/encoders_igrebot/config/encoders_igrebot_config.h
--- 
../../orig/aversive/modules/devices/encoders/encoders_igrebot/config/encoders_igrebot_config.h
      1970-01-01 01:00:00.000000000 +0100
+++ 
aversive/modules/devices/encoders/encoders_igrebot/config/encoders_igrebot_config.h
 2009-07-03 20:48:29.000000000 +0200
@@ -0,0 +1,33 @@
+/*  
+ *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)
+ *  Copyright I-Grebot (2009)
+ * 
+ *  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 : $$
+ *
+ */
+#ifndef _ENCODERS_IGREBOT_CONFIG_H_
+#define _ENCODERS_IGREBOT_CONFIG_H_
+
+
+/* For each encoder input, which programmable pin (RP#) to use */
+#define QUAD_ENCODER_1_PIN_A   6
+#define QUAD_ENCODER_1_PIN_B   7
+
+#define QUAD_ENCODER_2_PIN_A   15
+#define QUAD_ENCODER_2_PIN_B   13
+
+#endif
diff -uNr -x .svn -x '*.o' 
../../orig/aversive/modules/devices/encoders/encoders_igrebot/encoders_igrebot.c
 aversive/modules/devices/encoders/encoders_igrebot/encoders_igrebot.c
--- 
../../orig/aversive/modules/devices/encoders/encoders_igrebot/encoders_igrebot.c
    1970-01-01 01:00:00.000000000 +0100
+++ aversive/modules/devices/encoders/encoders_igrebot/encoders_igrebot.c       
2009-07-03 20:48:29.000000000 +0200
@@ -0,0 +1,115 @@
+/*  
+ *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)
+ *  Copyright I-Grebot(2009)
+ * 
+ *  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 : $$
+ *
+ */
+
+/** \file encoders_Igrebot.c
+ *  \brief Implementation for getting motor position
+ *
+ */
+
+#include <aversive.h>
+
+#include <encoders_igrebot.h>
+#include <encoders_igrebot_config.h>
+
+static int32_t value_codeur[2];
+static int16_t value_old[2];
+
+/** 
+ * Initialisation of encoders, variables
+ */
+void encoders_igrebot_init(void)
+{
+       POS1CNT=0;
+       POS2CNT=0;
+       QEI1CONbits.QEIM=0b111; //signal x4 + dépassement avec MAXxCNT
+       MAX1CNT=0xFFFF;
+       QEI1CONbits.SWPAB=0; //sens d'avance du codeur
+       QEI1CONbits.PCDOUT=0;//pas de sortie sur UPDNx
+
+       DFLT1CONbits.QEOUT=1; //Activation du filtrage en entrée
+       DFLT1CONbits.QECK=0;  //division par 1
+
+       QEI2CON=QEI1CON; //même config pour les deux codeurs
+       MAX2CNT=MAX1CNT;
+       DFLT2CON=DFLT1CON;
+       QEI2CONbits.SWPAB=0; 
+
+ 
+       /* Encodeurs */
+       RPINR14bits.QEA1R = QUAD_ENCODER_1_PIN_A;
+       RPINR14bits.QEB1R = QUAD_ENCODER_1_PIN_B;
+       
+       RPINR16bits.QEA2R = QUAD_ENCODER_2_PIN_A;
+       RPINR16bits.QEB2R = QUAD_ENCODER_2_PIN_B;
+}
+
+
+
+/** Extract encoder value.
+ *
+ * \param number : a (void *) that is casted in (int) containing the number
+ *                 of the encoder to be read.
+ */
+int32_t encoders_igrebot_get_value(void * number)
+{
+       int16_t value;
+       uint8_t flags;
+
+       IRQ_LOCK(flags);
+
+       int num = (int) number;
+
+       value = num ? (int16_t) POS2CNT : (int16_t) POS1CNT;
+
+       int16_t res = value - value_old[num];
+       value_old[num] = value;
+       value_codeur[num] += res;
+
+       IRQ_UNLOCK(flags);
+
+       return value_codeur[num];
+}
+
+/** Set an encoder value
+ *
+ * \param number : a (void *) that is casted in (int) containing the number
+ *                 of the encoder to be read.
+ * \param v      : the value
+ */
+void encoders_igrebot_set_value(void * number, int32_t v)
+{
+       uint8_t flags;
+       int num = (int) number;
+       int val = (int) v;
+       
+       IRQ_LOCK(flags);
+       
+       value_codeur[num]=val;
+       value_old[num]=val;
+
+       if (num == 0)
+               POS1CNT=val;
+       else 
+               POS2CNT=val;
+
+       IRQ_UNLOCK(flags);
+}
diff -uNr -x .svn -x '*.o' 
../../orig/aversive/modules/devices/encoders/encoders_igrebot/encoders_igrebot.h
 aversive/modules/devices/encoders/encoders_igrebot/encoders_igrebot.h
--- 
../../orig/aversive/modules/devices/encoders/encoders_igrebot/encoders_igrebot.h
    1970-01-01 01:00:00.000000000 +0100
+++ aversive/modules/devices/encoders/encoders_igrebot/encoders_igrebot.h       
2009-07-02 18:52:14.000000000 +0200
@@ -0,0 +1,47 @@
+/*  
+ *  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.h,v 1.4 2006-11-03 09:05:12 zer0 Exp $
+ *
+ */
+
+#ifndef _ENCODERS_IGREBOT_H_
+#define _ENCODERS_IGREBOT_H_
+
+/** 
+ * Initialisation of encoders, variables
+ */
+void encoders_igrebot_init(void);
+
+
+
+/** Extract encoder value.
+ *
+ * \param data : a (void *) that is casted in (uint8_t) containing the number
+ *               of the encoder to be read.
+ */
+int32_t encoders_igrebot_get_value(void * data);
+
+/** Set an encoder value
+ *
+ * \param data : a (void *) that is casted in (uint8_t) containing the number
+ *               of the encoder to be read.
+ * \param v    : the value
+ */
+void encoders_igrebot_set_value(void * data, int32_t c);
+
+#endif
diff -uNr -x .svn -x '*.o' 
../../orig/aversive/modules/devices/robot/position_manager/position_manager.c 
aversive/modules/devices/robot/position_manager/position_manager.c
--- 
../../orig/aversive/modules/devices/robot/position_manager/position_manager.c   
    2009-05-18 14:27:26.000000000 +0200
+++ aversive/modules/devices/robot/position_manager/position_manager.c  
2009-07-03 20:48:30.000000000 +0200
@@ -20,8 +20,8 @@
  */
 
 #include <string.h>
-#include <math.h>
 
+#include <aversive.h>
 #include <robot_system.h>
 #include <position_manager.h>
 
diff -uNr -x .svn -x '*.o' 
../../orig/aversive/modules/devices/robot/trajectory_manager/trajectory_manager.c
 aversive/modules/devices/robot/trajectory_manager/trajectory_manager.c
--- 
../../orig/aversive/modules/devices/robot/trajectory_manager/trajectory_manager.c
   2009-05-18 14:28:36.000000000 +0200
+++ aversive/modules/devices/robot/trajectory_manager/trajectory_manager.c      
2009-07-03 20:48:29.000000000 +0200
@@ -176,6 +176,16 @@
        return simple_modulo_2pi(res);
 }
 
+
+/** Get total distance travelled by the robot */
+double traj_get_distance(struct trajectory *traj)
+{
+       double d = ABS(rs_get_distance(traj->robot));
+       d = d / traj->position->phys.distance_imp_per_mm;
+       return d;
+}
+
+
 /** near the target (dist) ? */
 static uint8_t is_robot_in_dist_window(struct trajectory *traj, double d_win)
 {
diff -uNr -x .svn -x '*.o' 
../../orig/aversive/modules/devices/robot/trajectory_manager/trajectory_manager.h
 aversive/modules/devices/robot/trajectory_manager/trajectory_manager.h
--- 
../../orig/aversive/modules/devices/robot/trajectory_manager/trajectory_manager.h
   2009-05-02 12:03:04.000000000 +0200
+++ aversive/modules/devices/robot/trajectory_manager/trajectory_manager.h      
2009-07-03 20:48:29.000000000 +0200
@@ -106,6 +106,9 @@
  *  parameters */
 uint8_t trajectory_in_window(struct trajectory *traj, double d_win, double 
a_win_rad);
 
+/** Get total distance travelled by the robot */
+double traj_get_distance(struct trajectory *traj);
+
 /* simple commands */
 
 /** set relative angle and distance consign to 0 */
diff -uNr -x .svn -x '*.o' 
../../orig/aversive/modules/hardware/pwm_igrebot/config/pwm_config.h 
aversive/modules/hardware/pwm_igrebot/config/pwm_config.h
--- ../../orig/aversive/modules/hardware/pwm_igrebot/config/pwm_config.h        
1970-01-01 01:00:00.000000000 +0100
+++ aversive/modules/hardware/pwm_igrebot/config/pwm_config.h   2009-07-03 
20:48:30.000000000 +0200
@@ -0,0 +1,52 @@
+/*  
+ *  Copyright I-Grebot (2009)
+ * 
+ *  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: $
+ *
+ */
+
+/** \file pwm_config.h
+    \brief Module to operate all PWM outputs
+*/
+
+#ifndef _PWM_CONFIG_
+#define _PWM_CONFIG_
+
+#define MOT_DIR_G      LATAbits.LATA2
+#define TRIS_MOT_DIR_G TRISAbits.TRISA2
+
+#define MOT_DIR_D      LATBbits.LATB11
+#define TRIS_MOT_DIR_D TRISBbits.TRISB11
+
+
+/* Left motor is PWM1H1 */
+#define MOT_PWM_G      P1DC1
+#define TRIS_MOT_PWM_G TRISBbits.TRISB14
+#define MOT_G_FORWARD 1
+
+
+/* Right motor is PWM1H2 */
+#define MOT_PWM_D      P1DC2
+#define TRIS_MOT_PWM_D TRISBbits.TRISB12
+#define MOT_D_FORWARD 0
+
+
+#define MOT_G_BACKWARDS (1 - MOT_G_FORWARD)
+#define MOT_D_BACKWARDS (1 - MOT_D_FORWARD)
+
+#endif
+
diff -uNr -x .svn -x '*.o' 
../../orig/aversive/modules/hardware/pwm_igrebot/pwm_igrebot.c 
aversive/modules/hardware/pwm_igrebot/pwm_igrebot.c
--- ../../orig/aversive/modules/hardware/pwm_igrebot/pwm_igrebot.c      
1970-01-01 01:00:00.000000000 +0100
+++ aversive/modules/hardware/pwm_igrebot/pwm_igrebot.c 2009-07-03 
20:48:30.000000000 +0200
@@ -0,0 +1,136 @@
+/*  
+ *  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: pwm.c,v 1.13 2008-04-13 16:55:31 zer0 Exp $
+ *
+ */
+
+/* Droids-corp, Eirbot, Microb Technology 2005 - Zer0
+ * Implementation for PWM
+ */
+/** \file pwm.c
+ *  \brief Implementation for the PWM module.
+ *
+ *  \todo Test the module.
+ *
+ *  \test The modul fonctions and had been tested by Lamygalle.
+ *
+ * This module provides functions for using a pwm 
+ */
+
+#include <aversive.h>
+#include <stdio.h>
+
+#include "pwm.h"
+
+#include <aversive/parts.h>
+#include <pwm_config.h>
+
+/***********************************************************/
+
+/* PWM freq: (HZ) */
+#define FPWM 500
+#define PRESC 16
+
+#define PERIOD ((FCY / (FPWM * PRESC)) - 1)
+
+/* Maximum duty cycle :
+ * 100% duty cycle is when PxDCy is PxTPER x2
+ * since bit 0 is compared with the prescaler.
+ * This information is well hidden on figure 14-16
+ * page 14-33 of the PWM module datasheet.
+ */
+#define MAX_DUTY_PERCENT 100
+#define MAX_DUTY (2L * PERIOD * MAX_DUTY_PERCENT / 100)
+
+// global init
+void pwm_igrebot_init(void)
+{
+       P1TCONbits.PTMOD=0;//free running mode !
+       P1TCONbits.PTOPS=0;//postscaler 1:1
+       P1TCONbits.PTCKPS=2;//prescaler 1:16
+
+       P1TPER = PERIOD;
+       
+       PWM1CON1=0b0000001100110000; //output PWM1H et 2H
+
+       /* Configure tristates as outputs */
+       TRIS_MOT_DIR_G = 0;
+       TRIS_MOT_DIR_D = 0;
+       TRIS_MOT_PWM_G = 0;
+       TRIS_MOT_PWM_D = 0;
+
+       MOT_DIR_D = 1;
+       MOT_DIR_G = 1;
+
+       P1TCONbits.PTEN=1; //time base Enable
+}
+/***********************************************************/
+
+
+/***********************************************************/
+
+/* global SET FUNCTION : we use a (void *) to be compliant with
+ * control_system functions. For instance pwm_set((void *)(PWM1B_NUM), x) 
+ * is equivalent to pwm_set_1B(x) */
+void pwm_igrebot_set(void * data, int32_t value)
+{
+       uint8_t num = (uint8_t)(int)data;
+       S_MAX(value, MAX_DUTY);
+       
+       if (num == 1) {
+               /* Left motor */
+               if (value > 0) {
+                       MOT_DIR_G = MOT_G_FORWARD;
+               } else {        
+                       value = -value; 
+                       MOT_DIR_G = MOT_G_BACKWARDS;
+               }
+               MOT_PWM_G = (unsigned int) value;
+       } else {
+               /* Right motor */
+               if (value > 0) {
+                       MOT_DIR_D = MOT_D_FORWARD;
+               } else {        
+                       value = -value; 
+                       MOT_DIR_D = MOT_D_BACKWARDS;
+               }               
+               MOT_PWM_D = (unsigned int) value;       
+       }        
+}
+
+
+int32_t pwm_igrebot_get( void* data)
+{
+       uint8_t num = (uint8_t)(int)data;
+       int32_t value;  
+
+       if (num == 1) {
+               /* Left */
+               value = MOT_PWM_G;
+               if(MOT_DIR_G == MOT_G_BACKWARDS)
+                       value = -value; 
+       } else {
+               /* Right */
+               value = MOT_PWM_D;
+               if(MOT_DIR_D == MOT_D_BACKWARDS)
+                       value = -value; 
+       }        
+       return value;   
+}
+
+
diff -uNr -x .svn -x '*.o' 
../../orig/aversive/modules/hardware/pwm_igrebot/pwm_igrebot.h 
aversive/modules/hardware/pwm_igrebot/pwm_igrebot.h
--- ../../orig/aversive/modules/hardware/pwm_igrebot/pwm_igrebot.h      
1970-01-01 01:00:00.000000000 +0100
+++ aversive/modules/hardware/pwm_igrebot/pwm_igrebot.h 2009-07-03 
20:48:30.000000000 +0200
@@ -0,0 +1,54 @@
+/*  
+ *  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: pwm.h,v 1.12 2008-04-13 16:55:31 zer0 Exp $
+ *
+ */
+
+/* Droids-corp, Eirbot, Microb Technology 2005 - Zer0
+ * Implementation for PWM
+ */
+/** \file pwm.h
+ *  \brief Interface for the PWM module.
+ *
+ *  \todo Test the module.
+ *
+ *  \test No tests for the moment.
+ *
+ * This module provides functions for using a pwm 
+ */
+
+#ifndef _PWM_IGREBOT_H_
+#define _PWM_IGREBOT_H_
+
+#include <aversive.h>
+
+#include <pwm_config.h>
+
+/** global functions*/
+extern void pwm_igrebot_init(void);
+
+/** apply a PWM.
+ * \param data is a pointer that is casted in (uint8_t) to
+ *        specify the number of the PWM.
+ * \param value is the value of the pwm.
+ */
+extern void pwm_igrebot_set(void * data, int32_t value); 
+
+extern int32_t pwm_igrebot_get(void * data);
+
+#endif // _PWM_IGREBOT_H_
_______________________________________________
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

Répondre à