Difference between revisions of "Kladky s EV3"

From RoboWiki
Jump to: navigation, search
m
m (Software)
Line 10: Line 10:
  
 
==Software==
 
==Software==
My project has two components. One is the program that runs on the robot. The another one is a relay, that handles the messaging between the bots, because the bluetooth chip cannot be set to Master mode to connect to another device. So that's why there is a need of a relay.
+
Náš projekt je napísaný v Jave pre systém Lejos. Použili sme prostredie Eclipse a verziu JRE 1.6
  
I have written this in Python 3.5, because of the ease of use of the language.
+
Pri programovaní sme použili Lejos dokumentáciu [http://www.lejos.org/ev3/docs/].
The program uses two threads where opens the serial bluetooth connections given by the user, and relays the incoming messages from one thread to another.
+
 
For the serial connection I have used the pySerial python library, so to compile the relay code you have to download, and install it from pip or [https://pythonhosted.org/pyserial/].
+
Ukážka zdrojového kódu:
 +
 
 +
<code>
 +
public static void meraj() {
 +
  EncoderMotor em = new UnregulatedMotor(MotorPort.A);
 +
  EV3ColorSensor cs = new EV3ColorSensor(SensorPort.S1);
 +
  SensorMode sm = cs.getRedMode();
 +
   
 +
  int maxPower = 100;
 +
  int currPower = 5;
 +
  int draha = 5;
 +
  int last = 0;
 +
  int senzorAktive = -1;
 +
 +
  em.setPower(currPower);
 +
  em.forward();
 +
  while(true){
 +
      em.setPower(currPower);
 +
      draha = em.getTachoCount();
 +
      Delay.msDelay(1000);
 +
      LCD.drawInt(draha, 5, 5);
 +
      senzorAktive = ziskajDataZoSenzoru(cs);
 +
 
 +
      if (senzorAktive != -1) {
 +
        LCD.clear();
 +
em.stop();
 +
LCD.drawString("SILA ZDVIHU: ", 1, 4);
 +
LCD.drawInt(currPower, 5, 5);
 +
Delay.msDelay(20000);
 +
break;
 +
      }
 +
      if(draha == last) {
 +
        if(currPower < maxPower) {
 +
    currPower += 5;
 +
}
 +
if(currPower == maxPower) {
 +
    em.stop();
 +
    LCD.drawString("MOTOR NEMA POTREBNU SILU", 1, 5);
 +
    Delay.msDelay(5000);
 +
    break;
 +
  }
 +
      }
 +
      last = draha;
 +
      LCD.drawInt(last, 5, 4);
 +
  }
 +
}
 +
</code>

Revision as of 20:49, 16 June 2016

Project objective

Cieľom nášho prjektu bolo vytvorenie stavebnice, ktorá umožňuje meranie sily motora potrebnej na zdvihnutie telesa za pomoci kladky, alebo konfigúrácie kladiek. Daľšou úlohou bolo naprogramovanie programu, ktorý toto meranie riadi v zariadení EV3 v systéme Lejos.

Hardware

Pre účely tohto projektu sme použili EV3 zariadenie, EV3 Large servo motor a EV3 svetelný senzor. Súčasti hardvéru sme umiestnili do stvebnice.

Stavebnica.jpg Ev3.jpg Ev3ss.jpg Ev3lsm.jpg Ev3pohladH.jpg

Software

Náš projekt je napísaný v Jave pre systém Lejos. Použili sme prostredie Eclipse a verziu JRE 1.6

Pri programovaní sme použili Lejos dokumentáciu [1].

Ukážka zdrojového kódu:

public static void meraj() {

  EncoderMotor em = new UnregulatedMotor(MotorPort.A);
  EV3ColorSensor cs = new EV3ColorSensor(SensorPort.S1);
  SensorMode sm = cs.getRedMode();
   	
  int maxPower = 100;
  int currPower = 5;
  int draha = 5;
  int last = 0;
  int senzorAktive = -1;
  em.setPower(currPower);
  em.forward();
  while(true){
     em.setPower(currPower);
     draha = em.getTachoCount();
     Delay.msDelay(1000);
     LCD.drawInt(draha, 5, 5);
     senzorAktive = ziskajDataZoSenzoru(cs);
     if (senzorAktive != -1) {
        LCD.clear();

em.stop(); LCD.drawString("SILA ZDVIHU: ", 1, 4); LCD.drawInt(currPower, 5, 5); Delay.msDelay(20000); break;

     }
     if(draha == last) {
        if(currPower < maxPower) {

currPower += 5; } if(currPower == maxPower) { em.stop(); LCD.drawString("MOTOR NEMA POTREBNU SILU", 1, 5); Delay.msDelay(5000); break; }

     }
     last = draha;
     LCD.drawInt(last, 5, 4);
  }

}