📄 sickmodule.java
字号:
package cie.mobile.sick;
import name.lxm.robot.arch.*;
import java.io.IOException;
public class SickModule implements Module, Runnable
{
private static final String PORTNAME_MAP = "map";
private String module_name;
private SimpleOutPort port_map = null;
private ModuleDoc module_doc = null;
private LMS200 lms200 = null;
private Thread t_working = null;
private boolean bActive = false;
private RangeData mapData = null;
public SickModule()
{
port_map = new SimpleOutPort(this, PORTNAME_MAP);
System.out.println("SickModule has been constructed.");
}
public String getName()
{
return module_name;
}
public int getLayer()
{
return module_doc.getLayer();
}
public Port getPort(String name)
{
if(PORTNAME_MAP.equals(name))
return port_map;
return null;
}
public ModuleDoc getModuleDoc()
{
return module_doc;
}
public void init(ModuleDoc cfg) throws Exception
{
module_doc = cfg;
module_name = cfg.getName();
String com = cfg.getParamValue("com");
String baudrate = cfg.getParamValue("baudrate");
String mode = cfg.getParamValue("mode");
lms200 = new LMS200(com, mode, baudrate);
}
public void start() throws Exception
{
t_working = new Thread(this);
/*booting the LMS*/
lms200.start();
bActive = true;
t_working.start();
}
public void stop() throws Exception
{
bActive = false;
int i=0;
try{
Thread.sleep(50);
}catch(InterruptedException e){}
while(t_working.isAlive())
{
try{
Thread.sleep(50);
}catch(InterruptedException e){}
i++;
if(i>5) break;
}
t_working = null;
}
public void destroy() throws Exception
{
}
public void run()
{
while(bActive)
{
/*get a data frame*/
try{
mapData = lms200.getDataFrame();
}catch(IOException e)
{
e.printStackTrace();
break;
}
if(mapData != null)
{
/*send to port*/
port_map.setValue(this, mapData, 1000);
//System.out.println("Map Data has been send!");
}
/*Does it necessary to wait for a while?*/
try{
Thread.sleep(50);
}catch(InterruptedException e){}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -