Show Posts
Pages: [1] 2 3 ... 6
1  Using Arduino / Programming Questions / Re: PPM Decoder Problem on: February 24, 2012, 11:34:47 am
Hi,

first I just used a "c" not "cpp". Now I changed it to "cpp", and I added to PPM.h
Code:
#define DDR_ICP DDRB
#define PORT_ICP 0


Now I still get this error, I have already tried different names for the variable, but it's the same, every time.

Code:
PPM\PPM.cpp.o: In function `ppm_Init()':
C:\Program Files (x86)\arduino-1.0\libraries\PPM/PPM.cpp:25: multiple definition of `ppm_channel'
Servo_Controller.cpp.o:(.bss.ppm_channel+0x0): first defined here

Greetings
Philipp
2  Using Arduino / Programming Questions / PPM Decoder Problem on: February 24, 2012, 10:45:57 am
Hello,

I want to decode PPM Signals with an Arduino Duemilanove with a mega328. I have a "c" code, I want to usw in this program, but I only get a lot of Errors during compiling.
Code:
Servo_Controller.cpp.o: In function `loop':
C:\Users\Philipp\AppData\Local\Temp\build4028775172873483244.tmp/Servo_Controller.cpp:13: undefined reference to `ppm_Get(int)'
C:\Users\Philipp\AppData\Local\Temp\build4028775172873483244.tmp/Servo_Controller.cpp:14: undefined reference to `ppm_Get(int)'
C:\Users\Philipp\AppData\Local\Temp\build4028775172873483244.tmp/Servo_Controller.cpp:15: undefined reference to `ppm_Get(int)'
C:\Users\Philipp\AppData\Local\Temp\build4028775172873483244.tmp/Servo_Controller.cpp:16: undefined reference to `ppm_Get(int)'
C:\Users\Philipp\AppData\Local\Temp\build4028775172873483244.tmp/Servo_Controller.cpp:17: undefined reference to `ppm_Get(int)'
Servo_Controller.cpp.o:C:\Users\Philipp\AppData\Local\Temp\build4028775172873483244.tmp/Servo_Controller.cpp:18: more undefined references to `ppm_Get(int)' follow
Servo_Controller.cpp.o: In function `setup':
C:\Users\Philipp\AppData\Local\Temp\build4028775172873483244.tmp/Servo_Controller.cpp:8: undefined reference to `ppm_Init()'

The Arduino Code:
Code:
#include <PPM.h>

void setup(){
  Serial.begin(115200);
  ppm_Init();
}

void loop(){
  delay(250);
  Serial.print(ppm_Get(0),DEC);
  Serial.print(ppm_Get(1),DEC);
  Serial.print(ppm_Get(2),DEC);
  Serial.print(ppm_Get(3),DEC);
  Serial.print(ppm_Get(4),DEC);
  Serial.print(ppm_Get(5),DEC);
  Serial.println("--");
}

And the Lib, placed in the libraries folder in the folder "PPM"
Code:
#ifndef PPM_H_
#define PPM_H_



#define PPM_CHANNELS (6)

#ifndef F_CPU
#define F_CPU 16000000UL
#endif

#include <avr/io.h>
#include <avr/interrupt.h>



unsigned char ppm_channel[PPM_CHANNELS];

extern volatile char ppmNewData;
extern volatile char ppmValid;
extern volatile int chan;
extern volatile uint8_t last_ppm_state;

void ppm_Init();
unsigned char ppm_Get(int n);

#endif /* PPM_H_ */
Code:
#include "PPM.h"

volatile unsigned int ppm[PPM_CHANNELS];
volatile int chan = -1;

#define T_MIN ((1*F_CPU)/64/1000)
#define T_MAX ((2*F_CPU)/64/1000)
#define T_OUT ((3*F_CPU)/64/1000)

volatile char ppmNewData;
volatile char ppmValid;
volatile unsigned int timeOld;
volatile uint8_t last_ppm_state;


void ppm_Init()
{
    DDR_ICP &=~(1<<PORT_ICP);

TCCR1B =  (1<<CS11)|(1<<CS10); //Prescaler 64
TCCR1B |= (1<<ICNC1); //Noise canceler
//TCCR1B |= (1<<ICES1);   //Riseing edge, when bit is set
TIMSK1 = (1<<ICIE1) | (1<<OCIE1A);

ppmNewData = 0;
ppmValid = 0;
chan=-1;
}

ISR(TIMER1_COMPA_vect)
{
if(chan!=-1)
{

ppmNewData = 1;

/*PPM Decoding*/
/*ppmValid = 0xff;
char i;
for(i=0;i<PPM_CHANNELS;i++)
{
int tmp = ppm_Get(i);
if((tmp<5)||(tmp>250))
{
ppmValid = 0x00;
}
}*/

/**************/

}
else
{
ppmValid = 0;
}
chan=-1;
}

ISR(TIMER1_CAPT_vect)
{
unsigned int time=ICR1;
OCR1A=time+T_OUT;
if (time>timeOld)
{
time=time-timeOld;
}
else
{
time=time+(0xffff-timeOld)+1;
}
timeOld=ICR1;
if (chan>=0 && chan<PPM_CHANNELS)
{
ppm[chan]=time;
}
chan++;
}

unsigned char ppm_Get(int n) {
unsigned int t=ppm[n];

// conversion T_MIN...T_MAX -> 0...255
if (t<T_MIN) t=T_MIN;
t-=T_MIN;
t=t/((T_MAX-T_MIN)/255.0);
if (t>255.0) t=255.0;

return ((unsigned char)t);
}

I don't know, whats my fault. Can somebody please help me?

Greeting Philipp
3  Forum 2005-2010 (read only) / Troubleshooting / Servo is moving to the wrong position on: July 16, 2010, 04:17:30 am
Hi,

for my autopilot project, I want to let a servo go to a calculated position. But when I do this, the servo is moving to the 180 degrees positon and then back to the calculated positon.This happends each secound.
Code:
while(!wp1){
    get_gps();
    get_mh();
    calc.get_nwp_info(flat,flon,wpk1[0],wpk1[1],&distance,&qdm);
    new_servo_pos = calc.get_servo_pos((float)mh,qdm);
    se.write(new_servo_pos);
    delay(15);
    if(distance<1.0){
      wp1=true;
    }
    if(millis()>=time+2000){
      Serial.print("Welcher Wegpunkt: ");Serial.println("WP1");
      Serial.print("Start Lat: ");printFloat(flat,5);Serial.println("");
      Serial.print("Ziel Lat: ");printFloat(wpk1[0],5);Serial.println("");
      Serial.print("Lon: ");printFloat(flon,5);Serial.println("");
      Serial.print("Ziel Lon: ");printFloat(wpk1[1],5);Serial.println("");
      Serial.print("MH: ");Serial.println(mh);
      Serial.print("QDM: ");Serial.println(qdm);
      Serial.print("Servo: ");Serial.println(new_servo_pos);
      Serial.print("Fahrtregler: ");Serial.println(fahrt.read());
      Serial.print("Distance: ");Serial.println(distance);
      Serial.println("_______________________________________");
      time = millis();
    }
    Serial.println(se.read());
  }
This is the code from the project. I tried it at PWM, analog and normal ports. I used to Serial function to give out the data, and it's normal, in the variable I am saving the servo position is only the number the servo has to go to. Here is a part of it:
Code:
108
108
108
108
108
108
108
108
110
110
110
110
108
108
108
114
108
111
110
110
110
110
110
108
111
108
108
108
108
108
108
108
108
108
113
110
110
110
110
108
108
108
108
114
111
110
110
110
110
110
108
111
108
114
But why is the servo doing this?
Can somebody please help me?

Greetings
Philipp
4  Forum 2005-2010 (read only) / Syntax & Programs / Keyboard for Touchshield Slide on: July 30, 2010, 02:17:21 pm
Hi,
I need a Numberfield for entering Numbers, Points and Chars. I use the TButton function for that. This is the function:
Code:
int new_waypoint(int n){
  noStroke();
  fill(255);
  rect(73,0,247,240);
  stroke(0);
  zahl1.Paint();
  zahl2.Paint();
  zahl3.Paint();
  zahl4.Paint();
  zahl5.Paint();
  zahl6.Paint();
  zahl7.Paint();
  zahl8.Paint();
  zahl9.Paint();
  zahl0.Paint();
  zp.Paint();
  zc.Paint();
  zenter.Paint();
  zn.Paint();
  ze.Paint();
  fill(200,200,200);
  rect(110,30,190,40);
  char input_data[100];
  int i = 0;
  unsigned long time = millis();
  while(1){
    if(millis()>time+250){
      if(zahl1.GetTouch()){
        input_data[i] = '1';
        i++;
        fill(200,200,200);
        rect(110,30,190,40);
        fill(200,200,200);
        noFill();
        stroke(0);
        text(input_data,115,50,10);
        time = millis();
      }
      else if(zahl2.GetTouch()){
        input_data[i] = '2';
        i++;
        fill(200,200,200);
        rect(110,30,190,40);
        noFill();
        stroke(0);
        text(input_data,115,50,10);
        time = millis();
      }
      else if(zahl3.GetTouch()){
        input_data[i] = '3';
        i++;
        fill(200,200,200);
        rect(110,30,190,40);
        noFill();
        stroke(0);
        text(input_data,115,50,10);
        time = millis();
      }
      else if(zahl4.GetTouch()){
        input_data[i] = '4';
        i++;
        fill(200,200,200);
        rect(110,30,190,40);
        noFill();
        stroke(0);
        text(input_data,115,50,10);
        time = millis();
      }
      else if(zahl5.GetTouch()){
        input_data[i] = '5';
        i++;
        fill(200,200,200);
        rect(110,30,190,40);
        noFill();
        stroke(0);
        text(input_data,115,50,10);
        time = millis();
      }
      else if(zahl6.GetTouch()){
        input_data[i] = '6';
        i++;
        fill(200,200,200);
        rect(110,30,190,40);
        fill(200,200,200);
        noFill();
        stroke(0);
        text(input_data,115,50,10);
        time = millis();
      }
      else if(zahl7.GetTouch()){
        input_data[i] = '7';
        i++;
        fill(200,200,200);
        rect(110,30,190,40);
        noFill();
        stroke(0);
        text(input_data,115,50,10);
        time = millis();
      }
      else if(zahl8.GetTouch()){
        input_data[i] = '8';
        i++;
        fill(200,200,200);
        rect(110,30,190,40);
        noFill();
        stroke(0);
        text(input_data,115,50,10);
        time = millis();
      }
      else if(zahl9.GetTouch()){
        input_data[i] = '9';
        i++;
        fill(200,200,200);
        rect(110,30,190,40);
        noFill();
        stroke(0);
        text(input_data,115,50,10);
        time = millis();
      }
      else if(zahl0.GetTouch()){
        input_data[i] = '0';
        i++;
        fill(200,200,200);
        rect(110,30,190,40);
        noFill();
        stroke(0);
        text(input_data,115,50,10);
        time = millis();
      }
      else if(zn.GetTouch()){
        input_data[i] = 'N';
        i++;
        fill(200,200,200);
        rect(110,30,190,40);
        noFill();
        stroke(0);
        text(input_data,115,50,10);
        time = millis();
      }
      else if(ze.GetTouch()){
        input_data[i] = 'E';
        i++;
        fill(200,200,200);
        rect(110,30,190,40);
        noFill();
        stroke(0);
        text(input_data,115,50,10);
        time = millis();
      }
      else if(zc.GetTouch()){
        i--;
        input_data[i] = 0;
        fill(200,200,200);
        rect(110,30,190,40);
        noFill();
        stroke(0);
        text(input_data,115,50,10);
        time = millis();
      }
      else if(zp.GetTouch()){
        input_data[i] = '.';
        i++;
        fill(200,200,200);
        rect(110,30,190,40);
        noFill();
        stroke(0);
        text(input_data,115,50,10);
        time = millis();
      }
      else if(zenter.GetTouch()){
        char lat[10];
        char lon[10];
        i = 0;
        while(input_data[i]!='N'){
          lat[i] = input_data[i];
          i++;
        }
        lat[i] = '\0';
        i++;
        int e=0;
        while(input_data[i]!='E'){
          lon[e] = input_data[i];
          i++;
          e++;
        }
        lon[e] = '\0';
        waypoint_lat[n] = atof(lat);
        waypoint_lon[n] = atof(lon);
        return 1;
      }
    }
  }
}
I have a field with the numbers 0-9, with a point, a clear button, the chars N and E, and a Enter button. I want to add the chars to a char arrayw, when a button with numbers/chars is pressed. With the clear button, I want to clear the last entered char. At the end, the chars will look like that:
Code:
50.894238N10.473400E
Only the numbers will change. I want to convert the numbers, before the 'N' to a float and save it in waypoint_lat[n]. The number after 'N' will also be converted to a float a wil be saved in the waypoint_lon array.
In this movie can you see, what happends: http://autorino.onpw.de/wordpress/?p=222

After doing that, the Autopilot Site will be painted.
Code:
void autopilot_seite_paint(){
  noStroke();
  fill(255);
  rect(73,0,247,240);
  stroke(0);
  direct1.Paint();
  direct2.Paint();
  direct3.Paint();
  direct4.Paint();
  direct5.Paint();
  direct6.Paint();
  fill(200,200,200);
  rect(100,1,215,33);
  rect(100,41,215,33);
  rect(100,81,215,33);
  rect(100,121,215,33);
  rect(100,161,215,33);
  rect(100,201,215,33);
  stroke(0,0,0);
  fill(255);
  int n;
  for(int i=0;i<6;i++){
    char test[100];
    n=sprintf(test,"%f %f",waypoint_lat[i], waypoint_lon[i]);
    switch(i){
    case 0:
      text(test,110,15,10);
      break;
    case 1:
      text(test,110,55,10);
      break;
    case 2:
      text(test,110,95,10);
      break;
    case 3:
      text(test,110,135,10);
      break;
    case 4:
      text(test,110,175,10);
      break;
    case 5:
      text(test,110,215,10);
      break;
    }
  }
}
I use the sprintf function, to generate a char array for the waypoint_lat and _lon arrays. But there happens nothing.
Can you please help me whats wrong?

Greetings
Philipp
5  Forum 2005-2010 (read only) / Syntax & Programs / Problme mit decoding char array on: July 29, 2010, 05:27:28 pm
Hi,
I wrote a function, I can enter a char array with.
For example the array:
Code:
char array[] = {'5','2','.','5','2','1','N','1','0','.','2','6','2','8','E'};
And I want to decode it to:
"52.521"
and
"10.2628"
Then I want to convert it to float with atof.
This is the part from the function:
Code:
char lat[10];
        char lon[10];
        i = 0;
        while(input_data[i]!='N'){
          lat[i] = input_data[i];
          i++;
        }
        lat[i] = '\0';
        i++;
        int e=0;
        while(input_data[i]!='E'){
          lon[e] = input_data[i];
          i++;
          e++;
        }
        lon[e] = '\0';
        waypoint_lat[n] = atof(lat);
        waypoint_lon[n] = atof(lon);
        return 1;
The input_data char array is the arry with the incoming data from me.
But its not working.
Can somebody please help me?

Greetings
Philipp
6  Forum 2005-2010 (read only) / Syntax & Programs / Error with handing over an arry to a function on: July 29, 2010, 06:49:42 am
Hi,

I I wrote a function, but I get this error:
Code:
o: In function `loop':
undefined reference to `check_touch(int, int, int*)
This is the code:
Code:
boolean check_touch(int X, int Y, int field[]);

void setup(){
}

void loop(){
  int mouseY = 21;
  int mouseX = 2;
  int main_button[] = {2,6,3,5};
  if(check_touch((int)mouseX,(int)mouseY,main_button)){
    //Do Something
  }
}

boolean ckeck_touch(int X,int Y,int* field){
  if((X>field[0])&&(X<field[1])&&(Y>field[2])&&(Y<field[3])){
    return true;
  }
  else{
    return false;
  }
}

What is wrong? I can't find the mistake.

Greetings
Philipp
7  Forum 2005-2010 (read only) / Syntax & Programs / Max. 11 chars via Serial? on: July 25, 2010, 05:25:00 am
Hi,

I wrote a program, for getting Serial Inputs. This is the function for saving the incoming data in a array.
Code:
int in(){
  Serial.println("In in()");
  int i=0;
  while(1){
    indata[i] = (char)Serial.read();
    if(indata[i]=='$'){
      Serial.println("Return 1");
      Serial.println(indata);
      return 1;
    }
    i++;
  }
}
indata[] is a global char array.
I want to send strings linke that:
Code:
PS180F90B196$
NN52.94682873E10.47327$
The last char is ever a "$".
But when I try it, it's only possible to send 11 chars at the time.
I send:
Code:
PS180F180B180$
and this is the output
Code:
PS180F180B1ÿÿÿÿÿÿÿÿ8ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ0ÿÿÿÿÿÿÿÿÿÿÿÿÿ$
I tried it with a lot of different strings, and it's ever the same.

What can I do?

Greetings
Philipp
8  Forum 2005-2010 (read only) / Syntax & Programs / Re: Integer to char array on: July 09, 2010, 01:49:06 pm
thank's its working.

Philipp
9  Forum 2005-2010 (read only) / Syntax & Programs / Integer to char array on: July 09, 2010, 01:18:32 pm
Hi,

I need a possibility to convert a char array to a char array.
E.g.:
Code:
int i = 193;
[int to char array "e[]" ]
e[0] = '1';
e[1] = '9';
e[2] = '3';
What can I do?

Philipp
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: error: expected initializer before "gps_new" on: June 27, 2010, 04:08:40 pm
Thank you, it's working now.

Philipp
11  Forum 2005-2010 (read only) / Syntax & Programs / error: expected initializer before "gps_new" on: June 27, 2010, 12:09:07 pm
Hi,

I am writing my onw programm with the TinyGPS library for my GPS. But I always get this message: error: expected initializer before "gps new". But I don't know what's wrong.
Code:
#include <NewSoftSerial.h>
#include <TinyGPS.h>

TinyGPS gps;
NewSoftSerial nss(2, 3);

boolean gps_new;

boolean check_gps_new();
void show_gps();

void seup(){
  Serial.println(115200);
  nss.begin(9600);
  Serial.println("Ready...");
}

void loop(){
  gps_new = false;
  //gps_new = check_gps_new();
  if(check_gps_new){
    show_gps();
  }
}

boolean check gps_new(){
  while(nss.available()){
    if(gps.encode(nss.read()){
      return true;
    }else{
      return false;
    }
  }
}

void show_gps(){
  long lat, lon;
  float flat, flon;
  unsigned long age, date, time, chars;
  int year;
  byte month, day, hour, minute, second, hundredths;
  unsigned short sentences, failed;
  
  gps.get_position(&lat, &lon, &age);
  Serial.print(lat);Serial.print("  ")Serial.println(lon);
}

I hope somebody can help me.

Philipp
12  Forum 2005-2010 (read only) / Syntax & Programs / Problems with NewSoftSerial and GPS on: June 12, 2010, 11:40:13 am
Hi,
I just buyed a Venus GPS Modul. I tryed it, and it works, but now I want to work with the GPS Data. The GPS Sends in NMEA. Here is the code.
Code:
#include <NewSoftSerial.h>

NewSoftSerial gps(2,3);

char in[100];
char last;
char check;

void setup(){
  Serial.begin(115200);
  Serial.println("Ready...");
  
  gps.begin(9600);
}

void loop(){
  int i=0;
  if((gps.read()=='$')&&(gps.read()=='G')&&(gps.read()=='P')&&(gps.read()=='R')&&(gps.read()=='M')&&(gps.read()=='C')){
    while(last!='$'){
      last=gps.read();
      in[i]==last;
      i++;
    }
  }
  for(int i=0;i<100;i++){
    Serial.print(in[i]);
  }
  Serial.println("\n");
}
I want to read the GPRMC Data. But I don't works.
The programm is supposed to check, if the first letters are $GPRMC and then it shall the next information in the array in[].
Can you help me?
I connect the GPS RX pin to Arduino Pin 3 and the TX to Arduino Pin 2.
But I tryed it booth ways.

Philipp
13  Forum 2005-2010 (read only) / Development / Re: Expanding TinyGPS Library with distance function on: June 29, 2010, 04:53:53 am
Hi,

I just tryed it, and it seems to work. I wrote this into the TinyGPS.h:
Code:
void get_distance(float lat1, float lat2, float lon1, float lon2, float *course_, float *distance){
        float lat_dif;
        float lon_dif;

        *distance = sin(lat1/180.0*PI)*sin(lat2/180.0*PI) + cos(lat1/180.0*PI)*cos(lat2/180.0*PI)*cos((lon2/180.0*PI)-(lon1/180.0*PI));
        *distance = acos(*distance);
        *distance *= 6378.137*1000;

        lat_dif = lat1 - lat2;
        if(lat_dif<0){
            lat_dif *= (-1.0);
        }
        lon_dif = lon1 - lon2;
        if(lon_dif<0){
            lon_dif *= (-1.0);
        }

        lat_dif *= 60.0 * 1852.0;

        lon_dif *= 60.0;
        lon_dif *= cos(lat2*PI/180);
        lon_dif *= 1852.0;

        *course_ = atan(lon_dif/lat_dif)*180/PI;

        if((lat2<lat1)&&(lon2>lon1)){
            *course_ = 180.0 - *course_;
        }else if((lat2<lat1)&&(lon2<lon1)){
            *course_ = *course_ + 180.0;
        }else if((lat2>lat1)&&(lon2<lon1)){
            *course_ = 360.0 - *course_;
        }
    }

Philipp
14  Forum 2005-2010 (read only) / Development / Expanding TinyGPS Library with distance function on: June 29, 2010, 02:10:36 am
Hi,

I want to expand the TinyGPS Library with a "distance and course to the next way point" function. I have never wrote my own Header file before, so I don't know what to do. I already took a look into the file and also in the cpp file. What do I have to do for adding a new function?

Greetings
Philipp
15  Forum 2005-2010 (read only) / Development / Re: Problem with char array to int on: July 09, 2010, 01:36:11 pm
Ok,
but I wrote a new function now. And I have still problems. At the end of the function, I convert the servo, motor controller, and the bow_thrust arrays to an Integer. But I get wrong numbers at the end. When I only convert one of these arrays to an integer the number is right. Then I tried to print the numbers with the Serial Function. When I only print on of these arrays, I get the right number but when I print all arrays, I get wrong numbers.
Code:
void SerialEncode::encode_pwm(char encode[],int *se_,int *mc_,int *bt_)
{
    char actuel_char;
    char se[3];
    char mc[3];
    char bt[3];
    int i=3;
    int e=0;
    while (encode[i]!='$')
    {
        if (encode[i]=='S')
        {
            actuel_char = encode[i];
            e=0;
        }
        else if (encode[i]=='F')
        {
            actuel_char = encode[i];
            e=0;
        }
        else if (encode[i]=='B')
        {
            actuel_char = encode[i];
            e=0;
        }
        else
        {
            if (actuel_char=='S')
            {
                se[e] = encode[i];
                e++;
            }
            else if (actuel_char=='F')
            {
                mc[e] = encode[i];
                e++;
            }
            else if (actuel_char=='B')
            {
                bt[e] = encode[i];
                e++;
            }
        }
        i++;
    }
    //Serial.println(se);
    //Serial.println(mc);
    //Serial.println(bt);
    //*se_ = atoi(se);
    //*mc_ = atoi(mc);
    //*bt_ = atoi(bt);
}
When I clear the slashes in front of the three Serial.println, I get this ouput:
Code:
12345612
45612
12
When I clear only the slashes in front of one serial.println, I get the right number:
Code:
123
or
456
or
12

What is wrong?

Philipp
Pages: [1] 2 3 ... 6