Changeset 7
- Timestamp:
- 03/23/07 01:30:43 (2 years ago)
- Files:
-
- trunk/robots/rastor/db (deleted)
- trunk/robots/rastor/logging.cmd (added)
- trunk/src/logging.py (modified) (5 diffs)
- trunk/src/robot.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/logging.py
r1 r7 1 1 import os, sys, time 2 from frontend import *3 2 from network import * 4 3 from robot import Robot 5 from world import World6 4 7 5 #================================================================================= … … 18 16 19 17 # Initialize the world and all of its robots 20 self. world = World(cfg.world)18 self.robots = [] 21 19 for item in cfg.world.robot.items(): 22 20 robot = LogRobot(item[1], cfg.icehost, item[0]) 23 self. world.robots.append(robot)21 self.robots.append(robot) 24 22 25 23 def run(self): … … 32 30 def __init__(self, robotCfg, host, name): 33 31 Robot.__init__(self, robotCfg) 34 self.cmdLog = open(name + ".command.log", "w")35 32 self.poseLog = open(name + ".pose.log", "w") 36 37 self.cmdSub = CommandSubscriber(host, name + ":command", self.logCommand)38 33 self.poseSub = PoseSubscriber(host, name + ":pose", self.logPose) 39 34 … … 45 40 elif sensorCfg.type[:3] == "imu": 46 41 self.sensors[sid] = LogImu(sensorCfg, host, topic, name) 47 elif sensorCfg.type[:5] == "sonar":48 self.sensors[sid] = LogSonarArray(sensorCfg, host, topic, name)49 42 50 def logCommand(self, ts, v, w): 51 msg = str(ts) + " " + str(v) + " " + str(w) + "\n" 52 self.cmdLog.writelines(msg) 53 54 def logPose(self, ts, x, y, theta): 55 msg = str(ts) + " " + str(x) + " " + str(y) + str(theta) + "\n" 43 def logPose(self, ts, x, y, z, roll, pitch, yaw): 44 msg = str(ts) + " " + str(x) + " " + str(y) + " " + str(z) + " " + \ 45 str(roll) + " " + str(pitch) + " " + str(yaw) + "\n" 56 46 self.poseLog.writelines(msg) 57 47 … … 74 64 self.imuSub = ImuSubscriber(host, topic, self.logImu) 75 65 76 def logImu(self, ts, phi, theta, psi, p, q, r ):66 def logImu(self, ts, phi, theta, psi, p, q, r, fx, fy, fz): 77 67 msg = str(ts) + " " + str(phi) + " " + str(theta) + " " + str(psi) + " " \ 78 + str(p) + " " + str(q) + " " + str(r) + "\n" 68 + str(p) + " " + str(q) + " " + str(r) + " " + str(fx) + " " \ 69 + str(fy) + " " + str(fz) + "\n" 79 70 self.imuLog.writelines(msg) 80 81 #=================================================================================82 # LOGSONARARRAY --83 class LogSonarArray:84 def __init__(self, imuCfg, host, topic, name):85 self.sonarLog = open(name + ".sonar.log", "w")86 self.sonarSub = SonarArraySubscriber(host, topic, self.logSonarArray)87 88 def logSonarArray(self, ts, ranges):89 msg = str(ts)90 for r in ranges:91 msg += " " + str(r)92 msg += "\n"93 self.sonarLog.writelines(msg)94 71 95 72 if __name__ == "__main__": trunk/src/robot.py
r1 r7 1 1 from numpy import mat, float32 2 from geometry import *3 2 from math import degrees, radians 4 from sonars import SonarArray5 3 6 class UndefinedChassisType(Exception): pass7 4 class UndefinedBodyType(Exception): pass 8 5 … … 14 11 self.x = robotCfg.x 15 12 self.y = robotCfg.y 16 self.theta = radians(robotCfg.theta) 17 18 # Configure the chassis 19 chassisCfg = robotCfg.chassis 20 if chassisCfg.type[:4] == "diff": 21 self.chassis = DifferentialChassis(chassisCfg) 22 else: 23 raise UndefinedChassisType() 24 25 # Configure the body 26 bodyCfg = robotCfg.body 27 if bodyCfg.type[:3] == "box": 28 self.body = Box(Point(0., 0.), bodyCfg.length, bodyCfg.width) 29 elif bodyCfg.type[:4] == "circ": 30 self.body = Circle(Point(0., 0.), bodyCfg.radius) 31 else: 32 raise UndefinedBodyType() 13 self.z = robotCfg.z 14 self.roll = radians(robotCfg.roll) 15 self.pitch = radians(robotCfg.pitch) 16 self.yaw = radians(robotCfg.yaw) 33 17 34 18 # Define the sensor data structure 35 19 self.sensors = {} 36 37 def draw(self):38 self.drawBody(self.x, self.y, self.theta)39 self.drawSensors(self.x, self.y, self.theta)40 41 def drawBody(self, x, y, theta):42 glPushMatrix()43 glTranslatef(x, y, 0)44 glRotatef(degrees(theta), 0, 0, 1)45 glTranslatef(self.chassis.mountX, 0, 0)46 self.body.draw()47 glPopMatrix()48 49 def drawSensors(self, x, y, theta):50 glPushMatrix()51 glTranslatef(x, y, 0)52 glRotatef(degrees(theta), 0, 0, 1)53 for sensor in self.sensors.values():54 sensor.draw()55 glPopMatrix()56 57 #===============================================================================58 # DIFFERENTIALCHASSIS -- Models the robot as having two motors and a caster59 class DifferentialChassis:60 def __init__(self, chassisCfg):61 self.mountX = chassisCfg.mountX62 self.mountY = 0.5 * chassisCfg.axleLength63 self.wheelRadius = 0.5 * chassisCfg.wheelDiameter64 self.encTicsPerRev = chassisCfg.encTicsPerRev65
