Skip to content

Commit

Permalink
Merge pull request #9 from icns-distributed-cloud/v0.2.0
Browse files Browse the repository at this point in the history
implemented serial communication between aigo_controller(stm32 discovery board)
  • Loading branch information
icnslab authored Nov 29, 2021
2 parents dbf922d + 07888ec commit 9d2f768
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 25 deletions.
10 changes: 5 additions & 5 deletions aigo_nav/params/base_local_planner_params.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

TrajectoryPlannerROS:
max_vel_x: 0.4
max_vel_x: 2.0
min_vel_x: 0.0 # Allowing velocities too low will will stop the obstacle avoidance because low velocities won't actually be high enough to move the robot
max_vel_theta: 1.0
min_vel_theta: -1.0
max_vel_theta: 90.0
min_vel_theta: -90.0
min_in_place_vel_theta: 0.4

acc_lim_theta: 1.0
Expand All @@ -18,7 +18,7 @@ TrajectoryPlannerROS:

# Goal Tolerance Parameters
yaw_goal_tolerance: 3.14 # in rads
xy_goal_tolerance: 0.5 # in meters
xy_goal_tolerance: 0.1 # in meters
latch_xy_goal_tolerance: false

# Forward Simulation Parameters
Expand All @@ -45,6 +45,6 @@ TrajectoryPlannerROS:
publish_cost_grid_pc: true

# Oscillation Prevention Parameters
oscillation_reset_dist: 0.25 #How far the robot must travel in meters before oscillation flags are reset (double, default: 0.05)
oscillation_reset_dist: 0.9 #How far the robot must travel in meters before oscillation flags are reset (double, default: 0.05)
escape_reset_dist: 0.1
escape_reset_theta: 0.1
12 changes: 6 additions & 6 deletions aigo_nav/params/ekf_params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ekf_se_odom: # Used only for broadcasting odom to base_link transforms
false, false, false,
false, false, false,
false, false, true,
true, true, false]
false, false, false]
imu0_nodelay: false
imu0_differential: false
imu0_relative: false
Expand All @@ -65,8 +65,8 @@ process_noise_covariance: [5.05, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0.03, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0.03, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0.06, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 99999, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 99999, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0.04, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0.01, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.01, 0, 0, 0, 0,
Expand Down Expand Up @@ -158,7 +158,7 @@ ekf_se_map:
false, false, false,
false, false, false,
false, false, true,
true, true, false]
false, false, false]
imu0_nodelay: true
imu0_differential: false
imu0_relative: false
Expand All @@ -173,8 +173,8 @@ process_noise_covariance: [0.05, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0.03, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0.03, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0.06, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 99999, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 99999, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0.04, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0.01, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.01, 0, 0, 0, 0,
Expand Down
2 changes: 1 addition & 1 deletion aigo_nav/params/global_costmap_params.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
global_costmap:
global_frame: odom
robot_base_frame: base_link
update_frequency: 0.5
update_frequency: 0.167
publish_frequency: 10
static_map: false
width: 200.0
Expand Down
2 changes: 1 addition & 1 deletion aigo_nav/params/local_costmap_params.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local_costmap:
global_frame: odom
robot_base_frame: base_link
update_frequency: 5.0
update_frequency: 10.0
publish_frequency: 10.0
static_map: false
rolling_window: true
Expand Down
45 changes: 37 additions & 8 deletions aigo_serial/src/aigo_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,48 @@ def calculate_pose():
global right_vel
#in STM32, MOTOR_SPEED = OUTPUT * 15 (MOTOR_SPEED < 9000)
#turn right
mode = 0
if(left > right+50):
left_vel = 600
right_vel = -600
if (mode = 0):
left_vel = 600
right_vel = -600
mode = 1
elif (mode = 1):
left_vel = 200
right_vel = 200
mode = 2
elif (mode = 2):
left_vel = 600
right_vel = -600
mode = 3
elif (mode = 3):
left_vel = -200
right_vel = -200
mode = 0
#turn left
elif(left+50 < right):
left_vel = -600
right_vel = 600
if (mode = 0):
left_vel = -600
right_vel = 600
mode = 1
elif (mode = 1):
left_vel = 200
right_vel = 200
mode = 2
elif (mode = 2):
left_vel = -600
right_vel = 600
mode = 3
elif (mode = 3):
left_vel = -200
right_vel = -200
mode = 0
elif(left > 0 and right > 0):
left_vel = 400
right_vel = 400
left_vel = 300
right_vel = 300
elif(left < 0 and right < 0):
left_vel = -400
right_vel = -400
left_vel = -300
right_vel = -300
else:
left_vel = 0
right_vel = 0
Expand Down
142 changes: 142 additions & 0 deletions aigo_serial/src/aigo_serial_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#!/usr/bin/env python

import serial, time, rospy, re, os
from std_msgs.msg import Float32, Int32
from sensor_msgs.msg import LaserScan, Imu
ser_front = serial.Serial( \
port='/dev/ttyAMA2', \
baudrate=115200,
)
def left_callback(msg):
global left
left = msg.data

def right_callback(msg):
global right
right = msg.data

def calculate_pose():
global left_vel
global right_vel
#in STM32, MOTOR_SPEED = OUTPUT * 15 (MOTOR_SPEED < 9000)
#turn right
if(left > right+50):
left_vel = 600
right_vel = -600
#turn left
elif(left+50 < right):
left_vel = -600
right_vel = 600
elif(left > 0 and right > 0):
left_vel = 400
right_vel = 400
elif(left < 0 and right < 0):
left_vel = -400
right_vel = -400
else:
left_vel = 0
right_vel = 0


def is_int(s):
try:
int(s)
return True
except ValueError:
return False

def read_serial(): # read a serial data and determine source of the serial
serial_data = ser_front.readline()
ser_front.flushInput()
ser_front.flushOutput()
if serial_data[0:1] == "e":
serial_data = serial_data[1:]
read_encoder(serial_data)

def read_encoder(serial_data): # receive each side of encoder count from STM32F4 Discovery & convert to velocity
rate_data = []
encoder_data = []
# string -> integer
encoder_data = serial_data.split(',')
for i, v in enumerate(encoder_data):
if is_int(v) == True:
v = int(v)
if v > 8191: # reverse
v -= 16383
v *= 10
rate_data.append(v)
else:
return
tick_data[0] += rate_data[0]
tick_data[1] += rate_data[1]

lwheel_rate_msg.data = float(rate_data[0])
rwheel_rate_msg.data = float(rate_data[1])

lwheel_tick_msg.data = tick_data[0]
rwheel_tick_msg.data = tick_data[1]

# ticks : cumulative encoder ticks, rate : encoder ticks per second
if __name__ == '__main__':
rospy.init_node('aigo_serial') # initialize node

tick_data = [0, 0]
global left
global right
left = 0
right = 0
#lidar
#scan_pub = rospy.Publisher('scan', LaserScan, queue_size = 1)
#scan_msg = LaserScan()

#encoder_ticks
lwheel_tick_pub = rospy.Publisher('lwheel_ticks', Int32, queue_size = 1)
rwheel_tick_pub = rospy.Publisher('rwheel_ticks', Int32, queue_size = 1)

lwheel_rate_pub = rospy.Publisher('lwheel_rate', Float32, queue_size = 1)
rwheel_rate_pub = rospy.Publisher('rwheel_rate', Float32, queue_size = 1)

lwheel_tick_msg = Int32() # message type
rwheel_tick_msg = Int32()

lwheel_rate_msg = Float32()
rwheel_rate_msg = Float32()

lwheel_desired_rate_sub = rospy.Subscriber('lwheel_desired_rate', Int32, left_callback)
rwheel_desired_rate_sub = rospy.Subscriber('rwheel_desired_rate', Int32, right_callback)


#imu_pub = rospy.Publisher('imu', Imu, queue_size=1)
#imu_msg = Imu()

while not rospy.is_shutdown():
read_serial()

#publish encoder
lwheel_tick_pub.publish(lwheel_tick_msg)
lwheel_rate_pub.publish(lwheel_rate_msg)

rwheel_tick_pub.publish(rwheel_tick_msg)
rwheel_rate_pub.publish(rwheel_rate_msg)

#publish lidar
#scan_pub.publish(scan_msg)

#publish imu
#imu_pub.publish(imu_msg)
calculate_pose()
mytuple = (str(int(left_vel)), ",", str(int(right_vel)), "/")
#stm32_msg = str(left)+","+str(right)+"/"
stm32_msg = "".join(mytuple)
stm32_msg = stm32_msg.encode('utf-8')
ser_front.write(stm32_msg)
time.sleep(0.1)
left_vel = 0
right_vel = 0
mytuple = (str(300), ",", str(300), "/")
#stm32_msg = str(left)+","+str(right)+"/"
stm32_msg = "".join(mytuple)
stm32_msg = stm32_msg.encode('utf-8')
ser_front.write(stm32_msg)
ser_front.close()

4 changes: 2 additions & 2 deletions diff_drive/launch/aigo.launch
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

<arg name="ticks_per_meter" value="5363" />
<arg name="wheel_separation" value="0.2" />
<arg name="rate" value="2.0" />
<arg name="rate" value="3.0" />
<arg name="urdf_file" default="$(find aigo_urdf)/urdf/aigo.urdf" />
<param name="robot_description" command="$(find xacro)/xacro --inorder $(arg urdf_file)" />

<!-- Publish the robot state -->
<node name="robot_state_publisher" pkg="robot_state_publisher"
type="robot_state_publisher">
<param name="publish_frequency" value="2.0"/>
<param name="publish_frequency" value="10.0"/>
</node>

<!-- Provide simulated control of the robot joint angles -->
Expand Down
Loading

0 comments on commit 9d2f768

Please sign in to comment.