📄 controllergui.java
字号:
comm.sendInput(((ScriptEntry)scriptsModel.get(i)).cmd);
comm._connectCount=-1; //so we don't get it again
}
Vector menuitems;
synchronized(comm._menus) {
boolean titleDirty=false;
int index=comm._titles.size()-1;
for(Iterator it=comm._titles.iterator(); index>=0 && it.hasNext();index--) {
String entry=(String)it.next();
//if(!entry.equals((String)title.getItemAt(index))) {
// titleDirty=true;
// break;
//}
}
if(titleDirty) {
title.removeAllItems();//clearing the title popup menu, but we'll refresh the items if we're still connected
int len=0;
for(Iterator it=comm._titles.iterator(); it.hasNext();) {
String entry=(String)it.next();
title.insertItemAt(entry,0);
if(entry.length()>len)
len=entry.length();
}
title.setMaximumSize(new Dimension((int)(len*8)+25,title.getHeight()));
title.setSelectedIndex(0);
}
menuitems=(Vector)comm._menus.lastElement();
menuitems=(Vector)menuitems.clone();
}
//synchronized(this) {
menu.setValueIsAdjusting(true);
menu.setListData(menuitems);
Vector sels=new Vector();
for(int i=0; i<menuitems.size(); i++)
if(((ControllerListener.MenuEntry)menuitems.get(i)).selected)
sels.add(new Integer(i));
int[] selsArr=new int[sels.size()];
for(int i=0; i<selsArr.length; i++)
selsArr[i]=((Integer)sels.get(i)).intValue();
menu.setSelectedIndices(selsArr);
menu.setValueIsAdjusting(false);
//}
*
*/
//=============added above===========================
}
else{
//rawBtn.setEnabled(false);
//walkSerBtn.setEnabled(false);
/*
synchronized(menuScroll) {
title.removeAllItems();
title.addItem("-");
menu.setListData(new Vector());
status.setText("Reconnecting...");
status.setToolTipText("");
}
*/
}
//menuScroll.getViewport().setViewPosition(p);
//isUpdating=false;
comm._updatedFlag=false;
}
public void setEstopBtn(boolean b){
estopBtn.setEnabled(b);
}
//=============needed in EstopListener===============
public void estopUpdated(EStopListener l){
estopBtn.setText(estoplistener.getEStop()?"Un-Stop":"Stop!");
setEstopBtn(estoplistener._isConnected);
if (estoplistener.getEStop())
System.out.println("==>stopped");
else
System.out.println("==>stated!");
}
//===============needed in VisionUpdateListener=====
public void visionUpdated(VisionListener l) {
if(l.isConnected()!=connected) {
connected=l.isConnected();
}
if(connected) {
if(lastFrameTime==0) {
if(l.getTimeStamp()!=null)
lastFrameTime=l.getTimeStamp().getTime();
} else {
long cur=l.getTimeStamp().getTime();
mspf=mspf*mspfGamma+(cur-lastFrameTime)*(1-mspfGamma);
lastFrameTime=cur;
}
} else {
lastFrameTime=0;
}
}
public VisionPanel getVisionPane(){
return visionPane;
}
public void setVisionUpdatedListener(){
visionPane.getListener().addListener(this);
}
public void initControlPane(JPanel controlPane){
controlPane.setLayout(new BorderLayout());
pp=new PointPick(true,true);
Box temp=Box.createVerticalBox();
temp.add(Box.createVerticalStrut(10));
temp.add(new JLabel(" Walk Control GUI "));
temp.add(Box.createVerticalStrut(10));
controlPane.add(temp,BorderLayout.NORTH);
controlPane.add(pp,BorderLayout.CENTER);
pp.addPointPickedListener(this);
pp.addMouseListener(this);
pp.setEnabled(false);
Box tmp=Box.createHorizontalBox();
ButtonGroup bg = new ButtonGroup();
horizRotateBtn=new JRadioButton("Horizontal is Rotate ");
horizStrafeBtn=new JRadioButton("Horizontal is Strafe");
bg.add(horizRotateBtn);
bg.add(horizStrafeBtn);
horizRotateBtn.setSelected(true);
horizStrafeBtn.setSelected(false);
tmp.add(horizRotateBtn);
tmp.add(horizStrafeBtn);
horizRotateBtn.addActionListener(this);
horizStrafeBtn.addActionListener(this);
horizRotateBtn.setEnabled(false);
horizStrafeBtn.setEnabled(false);
controlPane.add(tmp,BorderLayout.SOUTH);
controlPane.add(Box.createHorizontalStrut(30),BorderLayout.WEST);
controlPane.add(Box.createHorizontalStrut(30),BorderLayout.EAST);
controlPane.setPreferredSize(new Dimension(300,300));
}
public void initHPPane(JPanel headPointPane){
headPointPane.setLayout(new BorderLayout());
pp1=new PointPick(true,false);
Box temp=Box.createVerticalBox();
temp.add(Box.createVerticalStrut(10));
temp.add(new JLabel(" HeadPoint Control GUI "));
temp.add(Box.createVerticalStrut(10));
headPointPane.add(temp,BorderLayout.NORTH);
headPointPane.add(temp,BorderLayout.NORTH);
headPointPane.add(pp1,BorderLayout.CENTER);
pp1.addPointPickedListener(this);
pp1.addMouseListener(this);
pp1.setEnabled(false);
Box tmp=Box.createHorizontalBox();
panBtn=new JRadioButton("Horizontal is Pan ");
rollBtn=new JRadioButton("Horizontal is Roll");
ButtonGroup bg1=new ButtonGroup();
bg1.add(panBtn);
bg1.add(rollBtn);
panBtn.setSelected(true);
rollBtn.setSelected(false);
tmp.add(panBtn);
tmp.add(rollBtn);
panBtn.addActionListener(this);
rollBtn.addActionListener(this);
panBtn.setEnabled(false);
rollBtn.setEnabled(false);
headPointPane.add(tmp,BorderLayout.SOUTH);
headPointPane.add(Box.createHorizontalStrut(30),BorderLayout.WEST);
headPointPane.add(Box.createHorizontalStrut(30),BorderLayout.EAST);
headPointPane.setPreferredSize(new Dimension(300,300));
}
public void pointPicked(Point2D.Float p, MouseEvent e, PointPick pp){
if(pp.ispp){
//System.out.println("===>ispp picked");
if(mechacomm.isConnected()){
///System.out.println(p.x+";;;;;"+p.y);
mechacomm.sendCommand("f", p.y);
//pp.doSetPoint(pp.getXValue(),p.y);
if(horizStrafeBtn.isSelected()){
mechacomm.sendCommand("s", -p.x);
//if(horizStrafeBtn.isSelected())
// pp.doSetPoint(p.x,pp.getYValue());
}else {
float aval=p.x;
aval*=(aval<0?aval:-aval);
mechacomm.sendCommand("r",aval);
//float tmp=pp.getYValue();
//if(horizRotateBtn.isSelected())
// pp.doSetPoint(p.x,pp.getYValue());
}
}
}else if (!pp.ispp){
if (hpcomm.isConnected()){
//System.out.println("===>is pp1 picked");
if(panBtn.isSelected())
hpcomm.sendCommand("p", -p.x);
if(rollBtn.isSelected())
hpcomm.sendCommand("r", p.x);
hpcomm.sendCommand("t", p.y);
}
}
}
public void headPointUpdated(HeadPointListener comm) {
pp1.setEnabled(hpcomm._isConnected);
panBtn.setEnabled(hpcomm._isConnected);
rollBtn.setEnabled(hpcomm._isConnected);
if(mechacomm._isConnected)
connectBtn.setEnabled(hpcomm._isConnected);
}
public void mechaUpdated(MechaController mc){
pp.setEnabled(mechacomm._isConnected);
horizRotateBtn.setEnabled(mechacomm._isConnected);
horizStrafeBtn.setEnabled(mechacomm._isConnected);
if(hpcomm._isConnected)
connectBtn.setEnabled(mechacomm._isConnected);
}
public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
pp.setPoint(0, 0);
}
public void rootCam(){
comm.sendInput("!root \"TekkotsuMon\" \"Raw Cam Server\"");
comm.dynObjSrcs.put("RawVisionGUI","\"TekkotsuMon\" \"Raw Cam Server\"");
}
public void rootWalkSer(){
comm.sendInput("!root \"TekkotsuMon\" \"Walk Remote Control\"");
comm.dynObjSrcs.put("WalkGUI","\"TekkotsuMon\" \"Walk Remote Control\"");
}
public void rootHPSer(){
comm.sendInput("!root \"TekkotsuMon\" \"Head Remote Control\"");
comm.dynObjSrcs.put("HeadGUI","\"TekkotsuMon\" \"Head Remote Control\"");
System.out.println("send root head romote control ");
}
public void callPane(){
//visionPane.fireConnect();
visionPane._listener=new UDPVisionListener(server,10011);
visionPane.fireConnect();
}
public void callControlPane(){
mechacomm=new MechaController(server,10050);
mechacomm.addMechaUpdatedListener(this);
}
public void callHPPane(){
hpcomm=new HeadPointListener(server,10052);
hpcomm.addHeadPointUpdatedListener(this);
}
/*
* building proc of ControllerGUI
*/
public ControllerGUI(String str){
super(str);
init();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ControllerGUI frame=new ControllerGUI("Sony Aibo teleoperation experiment");
frame.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -