test_ep_control.py
Go to the documentation of this file.
00001 #! /usr/bin/python
00002 
00003 import numpy as np, math
00004 import sys
00005 import pygame as pg
00006 
00007 import roslib
00008 roslib.load_manifest('equilibrium_point_control')
00009 roslib.load_manifest('hrl_lib')
00010 
00011 import rospy
00012 
00013 from equilibrium_point_control.ep_control import EPGenerator, EPC, EPStopConditions
00014 from hrl_lib.timer import Timer
00015 
00016 class TestEPGenerator(EPGenerator):
00017     def __init__(self, num_steps=1000):
00018         self.ind = 0
00019         self.pts = np.dstack([np.linspace(0, 0.5, num_steps),
00020                               np.linspace(-1, 2, num_steps),
00021                               np.linspace(1, -5, num_steps)])[0]
00022 
00023     def generate_ep(self):
00024         ep = self.pts[self.ind]
00025         stop = EPStopConditions.CONTINUE
00026         self.ind += 1
00027         return stop, ep
00028 
00029     def control_ep(self, ep):
00030         print "control_ep:", ep
00031 
00032     def clamp_ep(self, ep):
00033         return np.clip(ep, 0, 1)
00034 
00035     def terminate_check(self):
00036         if self.ind == len(self.pts):
00037             return EPStopConditions.SUCCESSFUL
00038         else:
00039             return EPStopConditions.CONTINUE
00040 
00041 def main():
00042     rospy.init_node('test_epc')
00043     pg.init()
00044     screen = pg.display.set_mode((300,300))
00045 
00046     test_gen = TestEPGenerator(100)
00047     test_epc = EPC('test_epc')
00048 
00049     # wait for keys p for pause and s for stop
00050     test_epc.last_time = rospy.get_time()
00051     def keyboard_cb(timer_event):
00052         pg.event.get()
00053         keys = pg.key.get_pressed()
00054         if keys[pg.K_s] or keys[pg.K_q]:
00055             test_epc.stop_epc = True
00056         if keys[pg.K_p] and rospy.get_time() - test_epc.last_time > 0.3:
00057             test_epc.pause_epc = not test_epc.pause_epc
00058             test_epc.last_time = rospy.get_time()
00059     Timer(rospy.Duration(0.1), keyboard_cb)
00060 
00061     test_epc.epc_motion(test_gen, 0.1, 10)
00062 
00063 if __name__ == '__main__':
00064     main()


equilibrium_point_control
Author(s): Advait Jain, Kelsey Hawkins. Advisor: Prof. Charlie Kemp (Healthcare Robotics Lab)
autogenerated on Wed Nov 27 2013 11:34:55