schade funktioniert nicht. der servo1 läuft wie er soll, aber der 2. servo läuft immer in die falsche richtung und nach dem helm zu befehl geht er nach der bewegung automatisch wieder in die grundstellung.
ich habe jetzt mal das beispiel von Arduino genommen (das Sweep servo beispiel)
also:
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
und hab mir die befehler rausgenommen.
sieht dann so aus:
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#include "SoftwareSerial.h"
SoftwareSerial port(12,13);
#else // Arduino 0022 - use modified NewSoftSerial
#include "WProgram.h"
#include "NewSoftSerial.h"
NewSoftSerial port(12,13);
#endif
#include <Servo.h> // Eingefügter Servo
Servo myservo;
#include <Servo.h> // Eingefügter Servo
Servo myservo2;
#include "EasyVR.h"
EasyVR easyvr(port);
int pos = 0; // variable to store the servo position
int pos2 = 0;
//Groups and Commands
enum Groups
{
GROUP_0 = 0,
GROUP_1 = 1,
};
enum Group0
{
G0_JARVIS = 0,
};
enum Group1
{
G1_HELM_AUF = 0,
G1_HELM_ZU = 1,
};
EasyVRBridge bridge;
int8_t group, idx;
void setup()
{
// bridge mode?
if (bridge.check())
{
cli();
bridge.loop(0, 1, 12, 13);
}
// run normally
Serial.begin(9600);
port.begin(9600);
if (!easyvr.detect())
{
Serial.println("EasyVR not detected!");
for (;;);
}
easyvr.setPinOutput(EasyVR::IO1, LOW);
Serial.println("EasyVR detected!");
easyvr.setTimeout(5);
easyvr.setLanguage(3);
group = EasyVR::TRIGGER; //<-- start group (customize)
myservo.attach(9);
myservo2.attach(7); // attaches the servo on pin 9 to the servo object
}
void action();
void loop()
{
easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)
Serial.print("Say a command in Group ");
Serial.println(group);
easyvr.recognizeCommand(group);
do
{
// can do some processing while waiting for a spoken command
}
while (!easyvr.hasFinished());
easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off
idx = easyvr.getWord();
if (idx >= 0)
{
// built-in trigger (ROBOT)
// group = GROUP_X; <-- jump to another group X
return;
}
idx = easyvr.getCommand();
if (idx >= 0)
{
// print debug message
uint8_t train = 0;
char name[32];
Serial.print("Command: ");
Serial.print(idx);
if (easyvr.dumpCommand(group, idx, name, train))
{
Serial.print(" = ");
Serial.println(name);
}
else
Serial.println();
easyvr.playSound(0, EasyVR::VOL_FULL);
// perform some action
action();
}
else // errors or timeout
{
if (easyvr.isTimeout())
Serial.println("Timed out, try again...");
int16_t err = easyvr.getError();
if (err >= 0)
{
Serial.print("Error ");
Serial.println(err, HEX);
}
}
}
void action()
{
switch (group)
{
case GROUP_0:
switch (idx)
{
case G0_JARVIS:
// write your action code here
group = GROUP_1;
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
}
break;
case GROUP_1:
switch (idx)
{
case G1_HELM_AUF:
// write your action code here
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos);
myservo2.write(pos-80); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
group = GROUP_0;
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
case G1_HELM_ZU:
// write your action code here
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
group = GROUP_0;
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
}
break;
}
}
da es mit 2 servos nciht klappt, nehm ich einen starken servo und hoffe dass mein gestell sich nciht verbiegt wenn es nur von einer seite angehoben wird.
leider hatt sich jetzt ein neues problem aufgetan.
nachdem ich einmal beide befehle gegeben habe, fängt der servo sich auf einmal an von selber ab und zu in irgend eine position zu bewegen.
spukt es in meinem servo?