00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 import wx
00033
00034 class JointPanel(wx.Panel):
00035 def __init__(self, parent, joint_name="joint", min_position=-3.14159, max_position=3.14159, max_velocity=100.0, max_effort=100.0, input_mode=True):
00036
00037
00038 self.joint_name = joint_name
00039 self.min_position = min_position
00040 self.max_position = max_position
00041 self.max_velocity = max_velocity
00042 self.max_effort = max_effort
00043 self.position = (max_position - min_position)/2 + min_position
00044 self.velocity = max_velocity/2
00045 self.effort = max_effort
00046 self.input_mode = input_mode
00047
00048
00049 self.slider_increments = 100
00050
00051
00052 wx.Panel.__init__(self, parent, wx.ID_ANY, style=wx.BORDER_SUNKEN)
00053
00054
00055 self.min_position_label = wx.StaticText(self, wx.ID_ANY, str(self.min_position))
00056 self.position_slider = wx.Slider(self, wx.ID_ANY, minValue=0, maxValue=self.slider_increments, style=wx.SL_AUTOTICKS | wx.SL_HORIZONTAL)
00057 self.position_slider.Enable(self.input_mode)
00058 self.max_position_label = wx.StaticText(self, wx.ID_ANY, str(self.max_position))
00059
00060 sizer_slider = wx.BoxSizer(wx.HORIZONTAL)
00061 sizer_slider.Add(self.min_position_label, 0, wx.CENTER | wx.ALL, 5)
00062 sizer_slider.Add(self.position_slider, 1, wx.CENTER)
00063 sizer_slider.Add(self.max_position_label, 0, wx.CENTER | wx.ALL, 5)
00064
00065
00066 self.position_label = wx.StaticText(self, wx.ID_ANY, "Position")
00067 self.position_text = wx.TextCtrl(self, wx.ID_ANY, style=wx.TE_PROCESS_ENTER)
00068 self.velocity_label = wx.StaticText(self, wx.ID_ANY, "Velocity")
00069 self.velocity_text = wx.TextCtrl(self, wx.ID_ANY, style=wx.TE_PROCESS_ENTER)
00070 self.effort_label = wx.StaticText(self, wx.ID_ANY, "Effort")
00071 self.effort_text = wx.TextCtrl(self, wx.ID_ANY, style=wx.TE_PROCESS_ENTER)
00072
00073 sizer_properties = wx.BoxSizer(wx.HORIZONTAL)
00074 sizer_properties.Add(self.position_label, 0, wx.CENTER | wx.ALL, 5)
00075 sizer_properties.Add(self.position_text, 0, wx.CENTER | wx.TOP | wx.BOTTOM | wx.LEFT, 5)
00076 sizer_properties.Add((1,1), 1, wx.CENTER)
00077 sizer_properties.Add(self.velocity_label, 0, wx.CENTER | wx.ALL, 5)
00078 sizer_properties.Add(self.velocity_text, 0, wx.CENTER | wx.TOP | wx.BOTTOM, 5)
00079 sizer_properties.Add((1,1), 1, wx.CENTER)
00080 sizer_properties.Add(self.effort_label, 0, wx.CENTER | wx.ALL, 5)
00081 sizer_properties.Add(self.effort_text, 0, wx.CENTER | wx.TOP | wx.BOTTOM | wx.RIGHT, 5)
00082
00083
00084 sizer_panel = wx.BoxSizer(wx.VERTICAL)
00085 sizer_panel.Add(sizer_slider, 0, wx.EXPAND)
00086 sizer_panel.Add(sizer_properties, 0, wx.EXPAND)
00087
00088 self.SetSizer(sizer_panel)
00089
00090
00091 if self.input_mode:
00092 self.position_slider.Bind(wx.EVT_SCROLL, self._on_slider_update)
00093 self.position_text.Bind(wx.EVT_TEXT_ENTER, self._on_position_update)
00094 self.position_text.Bind(wx.EVT_KILL_FOCUS, self._on_position_update)
00095 self.velocity_text.Bind(wx.EVT_TEXT_ENTER, self._on_velocity_update)
00096 self.velocity_text.Bind(wx.EVT_KILL_FOCUS, self._on_velocity_update)
00097 self.effort_text.Bind(wx.EVT_TEXT_ENTER, self._on_effort_update)
00098 self.effort_text.Bind(wx.EVT_KILL_FOCUS, self._on_effort_update)
00099
00100
00101 self.update_panel()
00102
00103 def update_panel(self):
00104 if (self.position is not None):
00105 self.position_slider.SetValue(self.position2slider(self.position))
00106 self.position_text.SetValue('%.5f' % self.position)
00107 else:
00108 self.position_slider.SetValue(self.position2slider(self.min_position))
00109 self.position_text.SetValue('')
00110 if (self.velocity is not None):
00111 self.velocity_text.SetValue('%.5f' % self.velocity)
00112 else:
00113 self.velocity_text.SetValue('')
00114 if (self.effort is not None):
00115 self.effort_text.SetValue('%.5f' % self.effort)
00116 else:
00117 self.effort_text.SetValue('')
00118
00119 def position2slider(self, position):
00120
00121 return int(round(self.slider_increments * (position - self.min_position) / (self.max_position - self.min_position)))
00122
00123 def slider2position(self, slider):
00124
00125 return (float(slider) / self.slider_increments * (self.max_position - self.min_position) + self.min_position)
00126
00127 def _on_slider_update(self, event):
00128 self.position = self.slider2position(self.position_slider.GetValue())
00129 self.update_panel()
00130
00131 def _on_position_update(self, event):
00132 try:
00133 self.position = float(self.position_text.GetValue())
00134 self.position = min(max(self.position, self.min_position), self.max_position)
00135 except:
00136 self.position = None
00137 self.update_panel()
00138
00139 def _on_velocity_update(self, event):
00140 try:
00141 self.velocity = float(self.velocity_text.GetValue())
00142 if self.velocity > self.max_velocity:
00143 self.velocity = self.max_velocity
00144 elif self.velocity < -self.max_velocity:
00145 self.velocity = -self.max_velocity
00146 except:
00147 self.velocity = None
00148 self.update_panel()
00149
00150 def _on_effort_update(self, event):
00151 try:
00152 self.effort = float(self.effort_text.GetValue())
00153 if self.effort > self.max_effort:
00154 self.effort = self.max_effort
00155 except:
00156 self.effort = None
00157 self.update_panel()
00158