diff --git a/bluedot_server/dotserver.py b/bluedot_server/dotserver.py index a32461da89679424fd10c88d68b3ef38a8943449..4156399b818591b200bff88ea52f9c4d9194a2c0 100644 --- a/bluedot_server/dotserver.py +++ b/bluedot_server/dotserver.py @@ -93,7 +93,7 @@ data1_ids={"lbrushcw":0,"lbrushccw":1,"none":2,"none":3,"rbrushcw":4,"rbrushccw" #extra out: # 24V DC 42V AC data2_ids={"col1":0,"col2":1,"col3":2,"col4":3,"blower":4,"none":5,"none":6,"none":7} -# 5V DC #special for reset line +# 5V DC #special for mock reset line data3_ids={"ampel_fwd":0,"ampel_bwd":1,"ampel_stop":2,"none":3,"reset":4, "none":5,"none":6,"none":7} #master_in: @@ -144,7 +144,7 @@ last_position=0 target_position=0 position_reached=False -maxposition=4 #number of screws triggering position sensor +maxposition=3 #number of screws triggering position sensor motion_block=0 @@ -423,6 +423,8 @@ def apply_motion_block(): global data1 global data2 + global auto + global homed global homing global position @@ -438,7 +440,7 @@ def apply_motion_block(): actual_track_speed = 0 target_track_speed= 0 last_track_speed=0 - + auto=False if (motion_block & (1<<data0_ids["bwd"]) !=0): @@ -447,13 +449,15 @@ def apply_motion_block(): actual_track_speed = 0 target_track_speed= 0 last_track_speed=0 + if homing: homing=False homed=True position=0 - position_reached=true - + position_reached=True + else: + auto=False if (motion_block & (1<<data0_ids["LL"]) !=0): print("stop LL") @@ -695,6 +699,8 @@ def sectimerevent(): global target_position global position_reached global target_track_speed + global target_left_speed + global target_right_speed global data3 global isresetpressed @@ -707,24 +713,52 @@ def sectimerevent(): print("position_reached") if auto_stop_requested: + print("stopping auto now") auto=False auto_stop_requested=False + target_left_speed=0 + target_right_speed=0 + target_track_speed=0 + else: if homed: - new_t=random.randint(1,maxposition+1) + new_t=random.randint(1,maxposition) while new_t==target_position: - new_t=random.randint(1,maxposition+1) + new_t=random.randint(0,maxposition) print("new target: ",new_t) - #target_position=new_t - #position_reached=False - #if target_position<position: - # target_track_speed=-20 - #else: - # target_track_speed=20 - + target_position=new_t + position_reached=False + if target_position<position: + target_track_speed=-20 + else: + target_track_speed=20 + + brush_active_L=random.randint(0,1) + if brush_active_L==0: + newleft=0 + print("newleftspeed:",newleft) + target_left_speed=newleft + else: + newleft=random.randint(-100,100) + while abs(newleft)<50: + newleft=random.randint(-100,100) + print("newleftspeed:",newleft) + target_left_speed=newleft + + brush_active_R=random.randint(0,1) + if brush_active_R==0: + newright=0 + print("newrightspeed:",newright) + target_right_speed=newright + else: + newright=random.randint(-100,100) + while abs(newright)<70: + newright=random.randint(-100,100) + print("newrightspeed:",newright) + target_right_speed=newright return @@ -885,6 +919,7 @@ def pressed(pos,id): global nextpumptarget global stoprequested + global auto_stop_requested global leftpressedts global rightpressedts @@ -920,6 +955,7 @@ def pressed(pos,id): if auto: auto_stop_requested=True + print("auto stop requested") else: auto=True home() @@ -933,11 +969,11 @@ def pressed(pos,id): stoprequested=True elif id=="fwd": - if (power and (motion_block & (1<<data0_ids["fwd"]) ==0)): + if ((not auto) and power and (motion_block & (1<<data0_ids["fwd"]) ==0)): target_track_speed=30 elif id=="bwd": - if (power and (motion_block & (1<<data0_ids["bwd"]) ==0)): + if ((not auto) and power and (motion_block & (1<<data0_ids["bwd"]) ==0)): target_track_speed=-30