Progetto nuovo Bobcat pala compatta.


buon giorno. sono uno studente dell'universita' di padova iscritto psicologia. sto realizzando un progetto utilizzando un make makey per progettare un nuovo tipo di cloche per una pala compatta bobcat.
sto passando ad arduino perche' code di cui necessito non possono essere scritti nel terminale di makey makey.
dovrei avere dei code per permettere alle mie due cloche di trasdurre il segnale input meccanico in elettrico output rilevabile da un computer che utilizza un software simulatore di tale bobcat.
nello specifico code dovrebbero riguardare l'utilizzo di due joysticks sotitutivi le cloche:
comando avanti (tutte due le cloche avanti contemporaneamente)
comando indietro (tutte due le cloche indietro contemporaneamente)
comando svolta destra (cloche sinistra avanti + cloche destra indietro)
comando svolta sinistra (cloche sinistra indietro + cloche destra avanti)

superiormente ad ogni yoystick e' montato uno stick playstation per controllare
il carrello e la pala.

nello specifico:
stick sinistro avanti (carrello su)
stick sinistro indietro (carrello giu')
stick destro avanti (apertura pala)
stick destro indietro (chiusura pala)

i comandi dovrebbero essere essere progressivi.

qualcuno potrebbe aiutarmi?

grazie anticipatamente.
buona giornata.
nicolo'

avevo già fatto stessa domanda nel forum inglese nel quale ho ricevuto alcune utili risposte.
ho provato ad usare code postati nel forum passandoli ad un professionista ma per questioni tempistiche mi ha chiesto se possibile di arrangiarmi perché è un periodo molto "busy" per lui.

vi passo quindi code ricevuti con le risposte.

vi ringrazio ancora per la cortese attenzione.

buona giornata.

nicolò

prima risposta

really - code dead simple; if can 1 joystick control single motor, duplicate , off go:

1. read joystick input (analogread() - value 0 - 1023)

2. map value positive/neg values (most likely) - map() -512 +511, instance.

3. send values out serial port, , code on other end (vr api interface or whatnot) need interpret them , apply them transformation matrix of excavator object and/or camera (all depend on how software works, scene graph, etc - goes beyond discussion)

4. each joystick - send serial stream data packet indicating values

actually - eliminate step 2 - send values of joysticks directly api, , mapping of values on pc end.

seconda risposta:


code: [select]
/ simple demonstration show how move servo joystick
//   or potentiometer servo not lose position
//   when joystick centres itself

#include <servo.h>

byte servopin = 7;  // servo signal connection
servo myservo;
int servopos = 90;
int servomax = 130;
int servomin = 45;
int servomove = 3;  // number of degrees per movement

byte potpin = a0;   // center pin of joystick or potentiometer connected here
int potvalue = 0;
int potcentre = 512; // adjust suit joystick
int potdeadrange = 50; // movements either side of centre ignored

unsigned long curmillis;
unsigned long readintervalmillis = 100;
unsigned long lastreadmillis;

void setup() {
  serial.begin(9600);
  serial.println("starting joystickservo.ino");
 
  myservo.attach(servopin);
  myservo.write(servopos);
}

void loop() {
  curmillis = millis();
  readjoystick();
  moveservo();
  showposition();
}

void readjoystick() {
        // check time
  if (curmillis - lastreadmillis >= readintervalmillis) {
     lastreadmillis += readintervalmillis;
        // read joystick
     potvalue = analogread(potpin);
        // figure if move required
     if (potvalue > potcentre + potdeadrange) {
        servopos += servomove;
     }
     if (potvalue < potcentre - potdeadrange) {
        servopos -= servomove;
     }
        // check values within limits
     if (servopos > servomax) {
        servopos = servomax;
     }
     if (servopos < servomin) {
        servopos = servomin;
     }
  }
}

void moveservo() {
  myservo.write(servopos);
}

void showposition() {
  serial.print("potvalue ");
  serial.print(potvalue);
  serial.print("   servopos ");
  serial.println(servopos);
}


Arduino Forum > International > Italiano > Generale (Moderator: leo72) > Progetto nuovo Bobcat pala compatta.


arduino

Comments