-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsec_buttonhandler.py
More file actions
68 lines (57 loc) · 2.44 KB
/
Copy pathsec_buttonhandler.py
File metadata and controls
68 lines (57 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import time
import rclpy
from rclpy.node import Node
from std_msgs.msg import String, Int32
from geometry_msgs.msg import Twist
from .main_head_control import HeadControl
from .sec_action import ActionPublisParam
class SecButtonSoccerNode(Node):
def __init__(self):
super().__init__('Sec_button_soccer_node')
self.action = ActionPublisParam()
self.create_subscription(
String, '/robotis/open_cr/button', self.button_callback, 10)
self.action_pub = self.create_publisher(
Int32,'/robotis/action/page_num', 10)
self.get_logger().info('Secondary Button Controller Ready')
self.is_walking = False
self.is_posisi = False
self.current_mode = 'walking'
self.double_click = 0.5
self.last_press_time = 0
def button_callback(self, msg: String):
button = msg.data
now = time.time()
if button == 'mode':
self.current_mode = 'walking'
self.executor.add_node(HeadControl())
self.get_logger().info('MODE → Walking Mode')
# self.enable_walking_mode()
elif button == 'start':
if self.is_walking == True:
self.get_logger().info('START → Stop Walking')
self.action.stop_walking()
self.is_walking = False
self.action.set_walking_state("Stop_jalan")
else:
self.last_press_time = now
self.get_logger().info('START → Jalan Diagonal')
self.action.action_param("walking_module")
time.sleep(0.5) # kasih waktu module aktif
self.action.start_walking()
self.action.set_walking_state("Jalan")
self.is_walking = True
self.action.start_recovery()
elif button == 'user':
if self.is_posisi == False:
self.get_logger().info("USER pressed → Init Pose")
self.action.action_param("action_module")
time.sleep(0.5) # kasih waktu module aktif
self.action.init_pose(9) # page init pose
self.is_posisi = False
else:
self.get_logger().info("USER pressed → bringup pose")
self.action.action_param("action_module")
time.sleep(0.5)
self.action.init_pose(15) #
self.is_posisi = True