Skip to content

Commit b5a2f39

Browse files
IT MOVES
1 parent 454bc7e commit b5a2f39

2 files changed

Lines changed: 63 additions & 10 deletions

File tree

GEMstack/onboard/interface/gem_gazebo.py

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
from dataclasses import replace
1515
from threading import Thread,Lock
1616

17+
from gazebo_msgs.srv import GetModelState, GetModelStateResponse
18+
from gazebo_msgs.msg import ModelState
19+
1720
from ackermann_msgs.msg import AckermannDrive
1821
import roslaunch
1922
# ROS Headers
@@ -88,6 +91,7 @@ def __init__(self, config):
8891
self.start = self.position[:]
8992
self.yaw = config.get('yaw',0)
9093

94+
9195
def to_agent_state(self) -> AgentState:
9296
pose = ObjectPose(frame=ObjectFrameEnum.ABSOLUTE_CARTESIAN,t=time.time(),x=self.position[0],y=self.position[1],yaw=self.yaw)
9397
activity = AgentActivityEnum.MOVING if self.velocity[0] != 0 or self.velocity[1] != 0 else AgentActivityEnum.STOPPED
@@ -130,6 +134,7 @@ def seek_target(self,target,dt):
130134
v -= AGENT_NOMINAL_ACCELERATION[self.type]*dt
131135
self.velocity = [v*direction[0],v*direction[1]]
132136
self.position = transforms.vector_madd(self.position,self.velocity,dt)
137+
133138

134139

135140
# class GEMDoubleIntegratorSimulation:
@@ -335,6 +340,8 @@ def __init__(self, scene : str = None):
335340
self.top_lidar_sub = None
336341
self.stereo_sub = None
337342
self.faults = []
343+
self.dt = settings.get('simulator.dt',0.01)
344+
338345

339346
self.dubins = SecondOrderDubinsCar(
340347
wheelAngleMin=settings.get('vehicle.geometry.min_wheel_angle'),
@@ -386,7 +393,21 @@ def __init__(self, scene : str = None):
386393

387394

388395
self.ackermann_pub = rospy.Publisher("ackermann_cmd", AckermannDrive, queue_size=1)
389-
396+
def getModelState(self):
397+
# Get the current state of the vehicle
398+
# Input: None
399+
# Output: ModelState, the state of the vehicle, contain the
400+
# position, orientation, linear velocity, angular velocity
401+
# of the vehicle
402+
rospy.wait_for_service('/gazebo/get_model_state')
403+
try:
404+
serviceResponse = rospy.ServiceProxy('/gazebo/get_model_state', GetModelState)
405+
resp = serviceResponse(model_name='gem_e4')
406+
except rospy.ServiceException as exc:
407+
rospy.loginfo("Service did not process request: "+str(exc))
408+
resp = GetModelStateResponse()
409+
resp.success = False
410+
return resp
390411

391412

392413
# Need to double check on this time
@@ -538,16 +559,37 @@ def callback_with_cv2(msg : Image):
538559

539560
def send_command(self, command : GEMVehicleCommand):
540561

541-
562+
print(command)
542563
t = self.time()
543564
if t < self.last_command_time + 1.0/self.max_send_rate:
544565
#skip command, PACMod can't handle commands this fast
545566
return
546567
self.last_command_time = t
547568

548-
#x,y,theta,v,phi = self.cur_vehicle_state
549-
550-
phi = ?????
569+
def extract_vehicle_info( currentPose):
570+
def quaternion_to_euler(x, y, z, w):
571+
t0 = +2.0 * (w * x + y * z)
572+
t1 = +1.0 - 2.0 * (x * x + y * y)
573+
roll = np.arctan2(t0, t1)
574+
t2 = +2.0 * (w * y - z * x)
575+
t2 = +1.0 if t2 > +1.0 else t2
576+
t2 = -1.0 if t2 < -1.0 else t2
577+
pitch = np.arcsin(t2)
578+
t3 = +2.0 * (w * z + x * y)
579+
t4 = +1.0 - 2.0 * (y * y + z * z)
580+
yaw = np.arctan2(t3, t4)
581+
return [roll, pitch, yaw]
582+
pos_x, pos_y, vel, yaw = 0, 0, 0, 0
583+
584+
pos_x = currentPose.pose.position.x
585+
pos_y = currentPose.pose.position.y
586+
vel = np.linalg.norm([currentPose.twist.linear.x, currentPose.twist.linear.y, currentPose.twist.linear.z])
587+
_,_, yaw = quaternion_to_euler(currentPose.pose.orientation.x, currentPose.pose.orientation.y, currentPose.pose.orientation.z, currentPose.pose.orientation.w)
588+
589+
590+
return pos_x, pos_y, vel, yaw # note that yaw is in radian
591+
#what is phi>>
592+
x,y,v,phi = extract_vehicle_info(self.getModelState())
551593

552594

553595

@@ -564,12 +606,14 @@ def send_command(self, command : GEMVehicleCommand):
564606
steering_angle_rate = front_wheel_angle_rate if phides > phi + phi_deadband else \
565607
(-front_wheel_angle_rate if phides < phi - phi_deadband else 0.0)
566608

567-
if command.brake_pedal_position > 0.0:
568-
acceleration = 0.0
609+
# if command.brake_pedal_position > 0.0:
610+
# acceleration = 0.0
611+
612+
569613

570614
msg = AckermannDrive()
571615
msg.acceleration = acceleration
572-
msg.speed = acceleration * self.dt #float('inf') if acceleration >0 else float('-inf')
616+
msg.speed = float('inf') if acceleration >0 else float('-inf') #acceleration * self.dt
573617
msg.steering_angle = phides
574618
msg.steering_angle_velocity = steering_angle_rate
575619

launch/gazebo_simulation.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ recovery:
1313
drive:
1414
perception:
1515
state_estimation : GNSSStateEstimator
16-
agent_detection : object_detection.ObjectDetection
16+
#agent_detection : object_detection.ObjectDetection
1717
perception_normalization : StandardPerceptionNormalizer
1818
planning:
1919
# relations_estimation: pedestrian_yield_logic.PedestrianYielder
@@ -73,7 +73,16 @@ variants:
7373
# state_estimation : OmniscientStateEstimator
7474
# agent_detection : OmniscientAgentDetector
7575
planning:
76-
trajectory_tracking:
76+
route_planning:
77+
type: StaticRoutePlanner
78+
args: [!relative_path '../GEMstack/knowledge/routes/xyhead_highbay_backlot_p.csv']
79+
motion_planning:
80+
type: RouteToTrajectoryPlanner
81+
args: [null] #desired speed in m/s. If null, this will keep the route untimed for the trajectory tracker
82+
trajectory_tracking:
83+
type: pure_pursuit.PurePursuitTrajectoryTracker
84+
args: {desired_speed: 2.5} #approximately 5mph
85+
print: False
7786
# visualization: !include "klampt_visualization.yaml"
7887
# visualization: !include "mpl_visualization.yaml"
7988
log_ros:

0 commit comments

Comments
 (0)