Difference between revisions of "Kladky s EV3"
m (→Software) |
(→Software) |
||
Line 20: | Line 20: | ||
EncoderMotor em = new UnregulatedMotor(MotorPort.A); | EncoderMotor em = new UnregulatedMotor(MotorPort.A); | ||
EV3ColorSensor cs = new EV3ColorSensor(SensorPort.S1); | EV3ColorSensor cs = new EV3ColorSensor(SensorPort.S1); | ||
− | SensorMode sm = cs.getRedMode(); | + | SensorMode sm = cs.getRedMode(); |
− | |||
int maxPower = 100; | int maxPower = 100; | ||
int currPower = 5; | int currPower = 5; | ||
int draha = 5; | int draha = 5; | ||
int last = 0; | int last = 0; | ||
− | int senzorAktive = -1; | + | int senzorAktive = -1; |
− | |||
em.setPower(currPower); | em.setPower(currPower); | ||
em.forward(); | em.forward(); | ||
Line 36: | Line 34: | ||
LCD.drawInt(draha, 5, 5); | LCD.drawInt(draha, 5, 5); | ||
senzorAktive = ziskajDataZoSenzoru(cs); | senzorAktive = ziskajDataZoSenzoru(cs); | ||
− | |||
if (senzorAktive != -1) { | if (senzorAktive != -1) { | ||
LCD.clear(); | LCD.clear(); |
Revision as of 19:50, 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.
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); }
}