module ActuatorControl::Functions

Public Instance Methods

activate_gui(_activatekey) click to toggle source
# File lib/vizkit/widgets/actuator_control/actuator_control.rb, line 36
def activate_gui(_activatekey)
        if (_activatekey == 0 )
                @_activategui = false
                @send_timer.stop if @send_timer
        elsif (_activatekey == 2 )
                @_activategui = true
                @send_timer.start(50) if @send_timer
        end
        
        # Slider
        surge_slider.setEnabled(@_activategui);
        sway_slider.setEnabled(@_activategui);
        heave_slider.setEnabled(@_activategui);                      
        roll_slider.setEnabled(@_activategui);
        pitch_slider.setEnabled(@_activategui);
        yaw_slider.setEnabled(@_activategui);
        # Spinbox
        surge_spinBox.setEnabled(@_activategui);
        sway_spinBox.setEnabled(@_activategui);
        heave_spinBox.setEnabled(@_activategui);
        roll_spinBox.setEnabled(@_activategui);
        pitch_spinBox.setEnabled(@_activategui);
        yaw_spinBox.setEnabled(@_activategui);
end
control(task_context,options=Hash.new) click to toggle source
# File lib/vizkit/widgets/actuator_control/actuator_control.rb, line 27
def control(task_context,options=Hash.new)                        
        @task_context = task_context
        @writer = task_context.actuator_command.writer 

        # Timer for sending command to Motor
        @send_timer = Qt::Timer.new(self)
        @send_timer.connect(SIGNAL(:timeout),self,:send_GuiValue)
end
heavevalue(_heavevalue) click to toggle source
# File lib/vizkit/widgets/actuator_control/actuator_control.rb, line 79
def heavevalue(_heavevalue)
                @op_message[2] = _heavevalue
end
initialise() click to toggle source
# File lib/vizkit/widgets/actuator_control/actuator_control.rb, line 3
def initialise
        # Connection betwenn the Signal and slot of sliders and spinbox is done using QT designer
        surge_slider.connect(SIGNAL('valueChanged(int)'),self,:surgevalue)
        sway_slider.connect(SIGNAL('valueChanged(int)'),self,:swayvalue)
        heave_slider.connect(SIGNAL('valueChanged(int)'),self,:heavevalue)
        roll_slider.connect(SIGNAL('valueChanged(int)'),self,:rollvalue)
        pitch_slider.connect(SIGNAL('valueChanged(int)'),self,:pitchvalue)
        yaw_slider.connect(SIGNAL('valueChanged(int)'),self,:yawvalue)

        activateGui_checkBox.connect(SIGNAL('stateChanged(int)'),self,:activate_gui)   
        pwmCtrl_checkBox.connect(SIGNAL('stateChanged(int)'),self,:pwmCtrl)   
        speedCtrl_checkBox.connect(SIGNAL('stateChanged(int)'),self,:speedCtrl)  
        
        # A local storage variable before sending the Gui output
        @op_message = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
        puts "now follows the op_message"
        puts @op_message
        puts "done"
        puts @op_message.methods        
        #@op_mode    = 0
        # A flag for checking whether activate_gui_control check box is checked or not
        @_activategui = false
end
pitchvalue(_pitchvalue) click to toggle source
# File lib/vizkit/widgets/actuator_control/actuator_control.rb, line 85
def pitchvalue(_pitchvalue)
        @op_message[4] = _pitchvalue
       end
pwmCtrl(_ctrlKey) click to toggle source
# File lib/vizkit/widgets/actuator_control/actuator_control.rb, line 61
def pwmCtrl(_ctrlKey)
        if (_ctrlKey == 2)
                @op_mode = 0                                 
               end
end
rollvalue(_rollvalue) click to toggle source
# File lib/vizkit/widgets/actuator_control/actuator_control.rb, line 82
def rollvalue(_rollvalue)
        @op_message[3] = _rollvalue
end
send_GuiValue() click to toggle source
# File lib/vizkit/widgets/actuator_control/actuator_control.rb, line 124
def send_GuiValue
        output_gui = @writer.new_sample
        for i in 0..5 do
                output_gui.target.push(@op_message[i].to_f / 100)
                output_gui.mode.push(:DM_UNINITIALIZED)
        end
        # Send Gui value
        @writer.write output_gui
end
speedCtrl(_ctrlKey) click to toggle source
# File lib/vizkit/widgets/actuator_control/actuator_control.rb, line 67
def speedCtrl(_ctrlKey)
 if (_ctrlKey == 2)
         @op_mode = 1                                
 end
end
surgevalue(_surgevalue) click to toggle source
# File lib/vizkit/widgets/actuator_control/actuator_control.rb, line 73
def surgevalue(_surgevalue)
        @op_message[0] = _surgevalue
end
swayvalue(_swayvalue) click to toggle source
# File lib/vizkit/widgets/actuator_control/actuator_control.rb, line 76
def swayvalue(_swayvalue)
        @op_message[1] = _swayvalue
end
update(input_gui, port_name) click to toggle source
# File lib/vizkit/widgets/actuator_control/actuator_control.rb, line 92
def update(input_gui, port_name)                     
        
        target = input_gui.target.to_a
        #mode = input_gui.mode.to_a
       # Reading the value from the joystick
       _surgevalue    = ( target[0] * 100 )
       _swayvalue     = ( target[1] * 100 )
       _heavevalue    = ( target[2] * 100 )
       _rollvalue     = ( target[3] * 100 )
       _pitchvalue    = ( target[4] * 100 )
       _yawvalue      = ( target[5] * 100 )

        #_surgemode  = mode[0]
        #_swaymode   = mode[1]
        #_heavemode  = mode[2]
        #_rollmode   = mode[3]
        #_pitchmode  = mode[4]
        #_yawmmmode  = mode[5]


       # Setting the joystick value to the gui
        if (@_activategui == false)
                      surge_slider.setValue(_surgevalue)
               sway_slider.setValue(_swayvalue)
               heave_slider.setValue(_heavevalue)
                roll_slider.setValue(_rollvalue)
                pitch_slider.setValue(_pitchvalue)
                yaw_slider.setValue(_yawvalue)                      
                @writer.write input_gui if @writer
        end
       end
yawvalue(_yawvalue) click to toggle source
# File lib/vizkit/widgets/actuator_control/actuator_control.rb, line 88
def yawvalue(_yawvalue)
        @op_message[5] = _yawvalue
end