From: Walter Fetter Lages Date: Sun, 20 May 2018 06:00:17 +0000 (-0300) Subject: Create command daemon on AIC. X-Git-Tag: v1.4.4^0 X-Git-Url: http://git.ece.ufrgs.br/?a=commitdiff_plain;h=efbe5184e56292f79fa755c4e7521a43b6528eef;p=aic.git Create command daemon on AIC. --- diff --git a/CmdDaemon/CmdDaemon.java b/CmdDaemon/CmdDaemon.java new file mode 100644 index 0000000..75ef6bc --- /dev/null +++ b/CmdDaemon/CmdDaemon.java @@ -0,0 +1,192 @@ +/****************************************************************************** + + Actuator Interface Card + Command Daemon + Copyright (C) 2005 Walter Fetter Lages + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + You can also obtain a copy of the GNU General Public License + at . + +*******************************************************************************/ + +import br.ufrgs.eletro.AIC.*; +import com.dalsemi.comm.*; +import com.dalsemi.system.*; +import java.io.*; +import java.lang.*; + +class CmdDaemon extends Thread +{ + static final int BASE=0x800000; + + static AIC aic; + static Host host; + static boolean debug=false; + static boolean udp=false; + static boolean help=false; + + public static void main(String[] args) throws IOException,CanBusException + { + int i; + int hostarg=0; + + System.out.println("AIC Command Daemon"); + System.out.println("Copyright (C) 2005 Walter Fetter Lages .\n"); + + switch(args.length) + { + case 0: + { + help=true; + break; + } + case 1: + { + if(args[0].equals("-debug") || + args[0].equals("-UDP")) help=true; + break; + } + case 2: + { + hostarg=1; + if(args[0].equals("-debug")) debug=true; + else help=true; + break; + } + case 3: + { + hostarg=1; + if(args[0].equals("-UDP")) udp=true; + else help=true; + break; + } + case 4: + { + hostarg=2; + if(args[0].equals("-debug")) debug=true; + else help=true; + if(args[1].equals("-UDP")) udp=true; + else help=true; + break; + } + default: + { + help=true; + } + } + + + if(help) + { + System.out.println("Usage:\tjava CmdDaemon.tini [-debug] aic_id"); + System.out.println("\tor"); + System.out.println("\tjava CmdDaemon.tini [-debug] -UDP controller_host status_port"); + System.exit(1); + } + try + { + aic=new AIC(BASE,24.0,20e3,2000); + if(udp) host=new HostUDP(args[hostarg],Integer.parseInt(args[hostarg+1])); + else host=new HostCAN(Integer.parseInt(args[hostarg])); + + GetCommand getCommand=new GetCommand(); + getCommand.setPriority(Thread.MAX_PRIORITY); + getCommand.start(); + + if(debug) System.out.println("getCommand priority="+getCommand.getPriority()); + } + catch (NumberFormatException nfe) + { + System.out.println("Usage: java CmdDaemon.tini [-debug] [-UDP controller_host port] | aicid"); + System.exit(1); + } + } +} + + +class GetCommand extends CmdDaemon +{ + public void run() + { + try + { + aic.on(); + aic.brake.release(); + + for(int k=0;;k++) + { + if(debug) System.out.print("k="+k+"\t"); + + int cmd=host.command(); + + if(debug) System.out.print("Command="+ cmd +"\t"); + + switch(cmd) + { + case Host.MOTOR_ON: + { + if(debug) System.out.print("Motor on\t"); + aic.motor.on(); + break; + } + case Host.MOTOR_OFF: + { + if(debug) System.out.print("Motor off\t"); + aic.motor.off(); + break; + } + case Host.MOTOR_ACT: + { + if(debug) System.out.print("Voltage="+host.voltage()+"\t"); + aic.motor.set(host.voltage()); + break; + } + case Host.BRAKE_RELEASE: + { + if(debug) System.out.print("Brake release\t"); + aic.brake.release(); + break; + } + case Host.BRAKE_APPLY: + { + if(debug) System.out.print("Brake apply\t"); + aic.brake.apply(); + break; + } +/* case Host.RESET: + { + if(debug) System.out.print("Reset\t"); + aic.reset(); + break; + } +*/ + default: + { + if(debug) System.out.print("Invalid\t"); + break; + } + + } + if(debug) System.out.println(""); + } + } + catch (Exception all) + { + all.printStackTrace(); + } + } +} diff --git a/CmdDaemon/Makefile b/CmdDaemon/Makefile new file mode 100644 index 0000000..c344464 --- /dev/null +++ b/CmdDaemon/Makefile @@ -0,0 +1,33 @@ +CLASSPATH=-classpath /opt/tini/bin/tini.jar:/opt/tini/bin/tiniclasses.jar:/opt/tini/bin/modules.jar:../lib/AIC.jar +APIDBPATH=-d /opt/tini/bin/tini.db +DEPPATH=-p /opt/tini/bin/modules.jar +DEPFILE=-x /opt/tini/bin/owapi_dep.txt +DEPNAME=-add CAN +LIBPATH=-path ../lib/AIC.jar +NATLIB=-n brake.tlib -n encoder.tlib -n index.tlib -n pwm.tlib +JAVAFLAGS=-O -target 1.1 -source 1.3 +TARGET= aic1 aic2 aic3 aic4 aic5 + +all: CmdDaemon.tini + +CmdDaemon.class: CmdDaemon.java ../lib/AIC.jar + javac ${JAVAFLAGS} ${CLASSPATH} CmdDaemon.java + +CmdDaemon.tini: CmdDaemon.class ../lib/AIC.jar + java ${CLASSPATH} BuildDependency ${DEPNAME} ${DEPFILE} ${DEPPATH} -f CmdDaemon.class ${APIDBPATH} -o CmdDaemon.tini ${LIBPATH} ${NATLIB} + +clean: + rm -f *.bak *~ *.class UPLOADED + +distclean: clean + rm -f CmdDaemon.tini + +upload: UPLOADED + +UPLOADED: CmdDaemon.tini + for i in ${TARGET}; do \ + ftp $$i < upload.ftp; \ + echo $$i uploaded; \ + done + + diff --git a/IODaemon/IODaemon.java b/IODaemon/IODaemon.java index 5edbf7b..023354f 100644 --- a/IODaemon/IODaemon.java +++ b/IODaemon/IODaemon.java @@ -32,7 +32,7 @@ import java.lang.*; class IODaemon extends Thread { static final int BASE=0x800000; - static final int ST=500; + static final int ST=50; static AIC aic; static Host host; diff --git a/Makefile b/Makefile index c2075f1..e4fb3ac 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ PACKAGES= doc \ PID \ StrobeTest \ DoorDaemon \ + CmdDaemon \ aicd \ braketst \ encodertst \ diff --git a/MotorTest/MotorTest.java b/MotorTest/MotorTest.java index 18f321b..fb2b079 100644 --- a/MotorTest/MotorTest.java +++ b/MotorTest/MotorTest.java @@ -62,12 +62,12 @@ class MotorTest aic.brake.release(); - for(i=0;(i <= 12) && run;i++) iter(i); + for(i=0;(i <= 24) && run;i++) iter(i); while(run) { - for(i=12;(i >= -12) && run;i--) iter(i); - for(i=-12;(i <= 12) && run;i++) iter(i); + for(i=24;(i >= -24) && run;i--) iter(i); + for(i=-24;(i <= 24) && run;i++) iter(i); } aic.off(); }