Professional Documents
Culture Documents
Hexbot Ros
Hexbot Ros
py
Saved: 12/16/15, 9:08:05 PM
1
2
3
4
5
Page 1 of 2
Printed For: Jayce Shea Chow
#!/usr/bin/env python
"""
Base structure for communicating with ROS
## = required for all ros programs, # = specific to this example
"""
6
7
8
9
10
11
12
# Jayce's Imports
import math
from numpy import *
13
14
15
16
# RJ's Imports
from HExBOT_move_RD import *
from Leg_RD import *
17
18
19
20
21
22
23
24
25
""" ## = required for all ros programs, # = specific to this example """
class HExBOT(object): # classes make things better, promise
""" This class encompasses the entire node """
def __init__(self):
''' setup ROS stuff '''
self.runrate = 3 #hertz
self.hexbot = Hexbot(self.runrate)
26
27
rospy.init_node('hexbot_control')
# initialize node
28
29
30
31
32
33
34
35
36
37
38
39
40
def run(self):
""" main run loop """
r = rospy.Rate(self.runrate) # sets rate for the program to run (Hz
# instead of while true, otherwice crtl+C doesn't work
41
42
43
44
45
/Users/jaycesheachow/Public/Hexbot_ROS.py
Saved: 12/16/15, 9:08:05 PM
46
Page 2 of 2
Printed For: Jayce Shea Chow
47
48
49
50
51
52
53
54
55
56
57
"""
# find next servo position
self.legpositions = hexy.movebot('walkforward', self.t, self.leg
self.out.data = self.legpositions
self.pub.publish(self.out)
# increment timestep
self.t += 1
if self.t >= 48:
self.t = 1
"""
58
59
60
61
self.hexbot.walkrate(0, 0, 1, self.runrate)
self.out.data = self.hexbot.legpositions
self.pub.publish(self.out)
62
63
64
# wait until next time this code should run (according to rospy.
r.sleep()
65
66
67
68
69
70
71
if __name__ == '__main__':
#run above code
node = HExBOT()
node.run()