Benutzer-Werkzeuge

Webseiten-Werkzeuge


Seitenleiste

projektews2013:wwsr:start:robotwlankrammitstepper
robotwlankrammitstepper.ino
// How to send OSC messages from an Arduino.
// This Example is in the public domain.
 
// Important known issues:
// The Wifly provides no means to get the data from a single UDP package at a time
// Everything is just dumped to the serial connection.
// The only hint that a package is finished is that reading from the serial *might* time out
// To make things work anyway:
// 1. Use a high baud rate for communication with the Wifly: 115200 on a hardware serial is perfect.
// 2. Adjust the timeout in server.availableCheck(). 2ms works fine with 115200baud.
// 3. If possible, let the controlling Program pause at least 1.5 times the timout between sending OSC messages.
 
#include <WiFlyHQ.h>
#include <ArdOSCForWiFlyHQ.h>
//#include <Servo.h> //nur für servovariante
//#include <SoftwareSerial.h>
//SoftwareSerial softSerial(2,3); // Rx is the recieving pin, Tx is the transmitting pin
 
WiFly wifly;
OSCServer server(&wifly);
//int winkel = 0;
int ledPin=13;
//Servo myservo;
//int wifiwert=1; //wird benutzt für nur 1 wert immer senden
int array[360]; //auf 180 für servovariante
int hoechsterWifiWert=-500;
//int ausrichtungsWinkel; //nur für servovariante
int step1=24; //stepper motor
int dir1=22; //stepper motor
 
//Rechtes Rad
int step2=26;
int dir2=28;
//Linkes Rad
int step3=30;
int dir3=32;
 
int startVariable=99;
 
 
void setup()
{ 
  //myservo.attach(22);
  //myservo.write(winkel);
  Serial.begin(115200);
  //use the convenient setup.
  wifly.setupForUDP<HardwareSerial>(
    &Serial3,   //the serial you want to use (this can also be a software serial)
    57600, // if you use a hardware serial, I would recommend the full 115200. This does not work with a software serial.
    true,	// should we try some other baudrates if the currently selected one fails?
    "wally",  //Your Wifi Name (SSID)
    "robomint", //Your Wifi Password 
    "WiFly",                 // Device name for identification in the network
    0,         // IP Adress of the Wifly. if 0 (without quotes), it will use dhcp to get an ip
    8000,                    // WiFly receive port
    "255.255.255.255",       // Where to send outgoing Osc messages. "255.255.255.255" will send to all hosts in the subnet
    8001,                     // outgoing port
    true	// show debug information on Serial
  );
  //wifly.printStatusInfo(); //print some debug information 
 
  pinMode(ledPin,OUTPUT); //prepare to fade th einternal LED by OSC
   // Register a callback fuction of the LED fading.
   // When a message is with the adress "/ard/ledFade" is received, "setLedFade" will be invoked.
   server.addCallback("/ard/ledFade",&setLedFade);
   wifly.startCommand();
   pinMode(step1, OUTPUT);
   pinMode(dir1, OUTPUT);
 
   pinMode(step2, OUTPUT);
   pinMode(dir2, OUTPUT);
   pinMode(step3, OUTPUT);
   pinMode(dir3, OUTPUT);
 
}
 
 
void loop()
{
  Serial.println(startVariable);
	//check for new incoming messages. If a message with a registered adress is recieved, the callback function will be invoked.
  if(server.availableCheck(2)>0)
  {  
    //debugoutln("alive!"); //callback after process
  }
  rotateStepper(225);
  }
  //myservo.write(ausrichtungsWinkel);
  //delay(10000);
  //hoechsterWifiWert=-500;
 
 
 
   //if(wifly.getRSSI()!=wifiwert){  //nur wenn sich was verändert wirds geprinted
   //..
   //  Serial.println(wifly.getRSSI());    //...
  //}
  //Serial.println(wifly.getRSSI());
 
 
void setLedFade(OSCMessage *_mes){
  //get 1st argument(int32) and use it to fade the LED
  int fadeValue=_mes->getArgInt32(0);
  Serial.println(fadeValue);
  analogWrite(ledPin,fadeValue );
}
 
void rotateStepper(int delayValue){    //entweder rotateStepper oder rotateServo in for schleife
 
  digitalWrite(dir1, LOW);
 
  for(int i=0;i<1600;i++) {
    digitalWrite(step1, HIGH);
    delay(delayValue);
    digitalWrite(step1, LOW);
    delay(delayValue);
    Serial.println(wifly.getRSSI());
  }
  digitalWrite(dir1, HIGH);
 
  for(int i=0;i<1600;i++) {  
    digitalWrite(step1, HIGH);
    delay(delayValue);
    digitalWrite(step1, LOW);
    delay(delayValue);
    Serial.println(wifly.getRSSI());
  }
}
/*
void rotateServo(){ //I<181 für servo
  for(int i=0;i<181;i++) {
 
    myservo.write(i); //servovariante
    delay(300);
    array[i]=wifly.getRSSI();
    Serial.println(wifly.getRSSI());
 
    if(array[i]>hoechsterWifiWert) {
      hoechsterWifiWert=array[i];
      ausrichtungsWinkel=i;
    }
  }
}
*/
projektews2013/wwsr/start/robotwlankrammitstepper.txt · Zuletzt geändert: 2016/01/21 12:45 (Externe Bearbeitung)