conflict when changing program from arduino uno to chipkit uno 32

hello everyone :slight_smile:

please someone helps me on my program ... firstly it's about making a wall avoidance bot and it works when using arduino uno but i have some errors i didn't succeed to resolve it ... please help me ...

D:\logiciels\mpide-0022-chipkit-win-20110530.\hardware\pic32\libraries\Servo\Servo.cpp: In function 'void handle_interrupts(timer16_Sequence_t, volatile __uint16_t*, volatile __uint16_t*)':
D:\logiciels\mpide-0022-chipkit-win-20110530.\hardware\pic32\libraries\Servo\Servo.cpp:95:30: warning: large integer implicitly truncated to unsigned type
D:\logiciels\mpide-0022-chipkit-win-20110530.\hardware\pic32\libraries\Servo\Servo.cpp: At global scope:
D:\logiciels\mpide-0022-chipkit-win-20110530.\hardware\pic32\libraries\Servo\Servo.cpp:105:8: error: expected constructor, destructor, or type conversion before '(' token
D:\logiciels\mpide-0022-chipkit-win-20110530.\hardware\pic32\libraries\Servo\Servo.cpp: In function 'void initISR(timer16_Sequence_t)':
D:\logiciels\mpide-0022-chipkit-win-20110530.\hardware\pic32\libraries\Servo\Servo.cpp:153:5: error: 'TCCR1A' was not declared in this scope
D:\logiciels\mpide-0022-chipkit-win-20110530.\hardware\pic32\libraries\Servo\Servo.cpp:154:5: error: 'TCCR1B' was not declared in this scope
D:\logiciels\mpide-0022-chipkit-win-20110530.\hardware\pic32\libraries\Servo\Servo.cpp:154:18: error: 'CS11' was not declared in this scope
D:\logiciels\mpide-0022-chipkit-win-20110530.\hardware\pic32\libraries\Servo\Servo.cpp:154:22: error: '_BV' was not declared in this scope
D:\logiciels\mpide-0022-chipkit-win-20110530.\hardware\pic32\libraries\Servo\Servo.cpp:155:5: error: 'TCNT1' was not declared in this scope
D:\logiciels\mpide-0022-chipkit-win-20110530.\hardware\pic32\libraries\Servo\Servo.cpp:161:5: error: 'TIFR1' was not declared in this scope
D:\logiciels\mpide-0022-chipkit-win-20110530.\hardware\pic32\libraries\Servo\Servo.cpp:161:18: error: 'OCF1A' was not declared in this scope
D:\logiciels\mpide-0022-chipkit-win-20110530.\hardware\pic32\libraries\Servo\Servo.cpp:162:5: error: 'TIMSK1' was not declared in this scope
D:\logiciels\mpide-0022-chipkit-win-20110530.\hardware\pic32\libraries\Servo\Servo.cpp:162:20: error: 'OCIE1A' was not declared in this scope
D:\logiciels\mpide-0022-chipkit-win-20110530.\hardware\pic32\libraries\Servo\Servo.cpp: In member function 'void Servo::writeMicroseconds(int)':
D:\logiciels\mpide-0022-chipkit-win-20110530.\hardware\pic32\libraries\Servo\Servo.cpp:313:23: error: 'SREG' was not declared in this scope
D:\logiciels\mpide-0022-chipkit-win-20110530.\hardware\pic32\libraries\Servo\Servo.cpp:314:9: error: 'cli' was not declared in this scope

and this is my program

#include <Servo.h>
 
#define AVANT 1
#define ARRIERE 0
#define GAUCHE 2
#define DROITE 3
 
#define SERVOG 1
#define SERVOD 0
 
#define SHARP 4
 
#define VMAX 5
 
Servo servog;
Servo servod;
 
int vLdr = 5;
 
int getNeutral(int s)
{
  if(s == SERVOG)
    return 86;
  else
    return 84;
}
 
 
void handleS(int s, int speed)
{
  //Vitesse :
  // 0 -> 0; 1 -> 1; 2 -> 3; 3 -> 8; 4 -> 10; v => 5 -> 30
  int tab[6] = {0,1,3,8,10,30};
  int pos = getNeutral(s);
 
  int acc;
  if (speed < 0)
    acc = - tab[abs(speed)];
  else
    acc = tab[speed];
   
  if(s == SERVOG)
      servog.write(pos += acc);
  else
      servod.write(pos -= acc);
}
 
 
void move(int direction)
{
  int m1 = 0, m2 = 0;
  switch(direction)
  {
    case DROITE: m1 = 1; m2 = -1; break;
    case GAUCHE: m1 = -1; m2 = 1; break;
    case AVANT: m1 = 1; m2 = 1; break;
    case ARRIERE: m1 = -1; m2 = -1; break;
  }
  handleS(SERVOG, m1*VMAX);
  handleS(SERVOD, m2*VMAX);  
}  
 
void sharp()
{
   int v =  analogRead(SHARP);
      if (v >= 180)
      {
        move(ARRIERE);
        delay(300);
        move(DROITE);
        delay(900);
      }
      else if (v >= 100)
      {
        handleS(SERVOG, VMAX);
        handleS(SERVOD, 0);
        delay(1500);
      }
}
void setup()
{

  Serial.begin(9600);
  servog.attach(10);
  servod.attach(9);
  move(AVANT);
}
 
void loop()
{
       sharp();
     move(AVANT);
    delay(100);
}

1st, I say you may get better support over on the chipkit forum as the folks here tend to not be as familiar
with the pic32 environment.

What you are seeing is that there is AVR code in your servo library code and it obviously
fails when compiling for the pic32 processor.

You definitely have an old mpide release.
I looked in my 0022 mpide release (from Aug 2011 vs your May 2011) in and my servo library does not have any AVR code in it.

But there is a more recent version of mpide.
Rather than figure out what is wrong with release you have, go get the 0023 version
there were many fixes and updates since the mpide 0022 release.

--- bill

thank you very much ill try to update my mpide but firstly can you tell me what's the AVR code because im a little beginner in programming :slight_smile:

TCCR1A, TCCR1B, ... , SREG

Are references to AVR hardware registers.
Those registers do not exist on the pic32.

--- bill

zizouali:
thank you very much ill try to update my mpide but firstly can you tell me what's the AVR code because im a little beginner in programming :slight_smile:

Seriously, look for Chipkit examples. If you are a beginner it is like trying to learn to fly a plane with a German instructor, when you don't speak German.

The language spoken for both boards & environments is "Arduino"
so for this specific case, I don't think knowing the underlying AVR vs pic32 low level specifics should be necessary
since the Arduino sketch is written to use the Arduino servo library and sounds like it works with the servo library on the AVR
based Arduino platform.

From the error messages, the problem is that servo library in the pic32 specific library area is written for the AVR
using AVR specific registers.

While I don't know if the pic32 code servo library code works correctly, the mpide releases
0022 from Aug 2011 or 0023 from Nov 2011 do not contain any AVR code
in the pic32 specific servo library.

The example sketch above does compile with the mpide 0023 from 2011-12-21

(At least on linux - I don't use Windows or Mac OS for anything so I can't speak for those versions)

Note: it failed to compile with mpide 0022 20110822 (header file problems)

--- bill

well i already fixed it .. it was because of Mpide compability and i downloaded the new one and it works perfectly ... anyway thank you all and one other thing can someone help me how to receive data from BeagleBoard with serial USB ...