Skip to content

Instantly share code, notes, and snippets.

@jones2126
jones2126 / AS5048B_using_360_degrees_v2.cpp
Last active May 16, 2020 21:26
Read an AMS AS5048B using an Arduino based microcontroller and print the RPM
/**
AS5048B_using_360_degrees_v2.cpp
The sensor will read and calculate the meters travelled at 10 Hz
m/s and RPM will be calculated each time a print is performed every 2 seconds (0.5 HZ) using meters travelled as input.
Therefore m/s and RPM will averaged for that 2 second period
*/
@jones2126
jones2126 / cmd_vel_pub.py
Last active May 18, 2020 22:00
Python script to read text file with multiple linear.x and angular.z instructions and publish for ROS cmd_vel topic
#!/usr/bin/env python
"""
Produces cmd_vel statements based on input entered into a text file in the format:
linear.x, angular.z, duration (seconds)
0.5, 0.0, 10 <---- 0.5 m/s, go straight for 10 seconds
1.5, 1.0, 15 <---- 1.5 m/s, full left? for 15 seconds
An example command to access one element of the table that is loaded: print(mission_commands[2][1]) # row 2, element 1 - remember 0 reference
The .txt file needs at least two entries otherwise you will get the error: IndexError: invalid index to scalar variable.
@jones2126
jones2126 / encoder_track.cpp
Last active June 7, 2020 13:03
Testing code from Jeff to keep track of encoder
/*
Program to track the absolute position of an AMS_AS5048B encoder since CPU reset even though the encoder rolls over the 14bit register 0-16348 that is built in.
In other words, the encoder can keep spinning and this program keeps track of the total rotations/distance travelled or however you want to represent
knowing the absolute position. The value of "ticks" will be stored in "rotational_position".
*/
#include <Wire.h>
//unit consts
@jones2126
jones2126 / front_angle_v6.cpp
Last active June 19, 2020 15:00
Read AMS-5048B angle sensor and publish ROS topic for the steering angle
/*
front_angle_v6.cpp
Read the AMS-5048B angle sensor and publish the steering angle - front_angle_raw = the raw value of the sensor
This program will also read an analog potentiometer during setup to make sure the wheels are pointing straight.
The program will track the absolute position of an AMS_AS5048B encoder since CPU reset even though the encoder rolls over the 14bit register 0-16348
that is built in. In other words, the encoder can keep spinning and this program keeps track of the total rotations/distance travelled or
@jones2126
jones2126 / meters_traveled_v1.py
Last active June 20, 2020 13:26
Produces cmd_vel statements based on input entered into a text file to move a defined set of meters ahead
#!/usr/bin/env python
"""
Produces cmd_vel statements based on input entered into a text file in the format:
linear.x, angular.z, distance (meters)
0.5, 0.0, 10 <---- 0.5 m/s, go straight for 10 meters
1.5, 1.0, 15 <---- 1.5 m/s, full left? for 15 meters
An example command to access one element of the table that is loaded: print(mission_commands[2][1]) # row 2, element 1 - remember 0 reference
The .txt file needs at least two entries otherwise you will get the error: IndexError: invalid index to scalar variable.
@jones2126
jones2126 / left_speed_sensor_v4.cpp
Created June 19, 2020 15:03
Reads the AS5048B, calculates speed and distance traveled and publishes the values using ROS
/*
left_speed_sensor_v4.cpp
Reads AS5048B using a Teensy 3.2 and I2C communiction
This reads the sensor, calculates speed and distance travelled and publishes the values using ROS to output the data.
The frequency at which the AS5048B is read is set using: poll_AS5048B_Interval
The frequency at which the RPM is displayed as a ROS info statement is set using: infoInterval
@jones2126
jones2126 / driver.py
Created August 22, 2020 18:53
Updated driver.py from nmea_navsat_driver to filter speed <0.1 m/s
# Software License Agreement (BSD License)
#
# Copyright (c) 2013, Eric Perko
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
@jones2126
jones2126 / check_yaw_from_odom.py
Last active August 23, 2020 17:27
Reads quaternion from Odometry and uses euler_from_quaternion function to print the yaw value in radians and degrees
#!/usr/bin/env python
# check_yaw_from_odom.py
# Running Turtlebot in simulation yaw ranges from 3.14 to -3.14
# which converts in degrees to 180 degrees and -180 degrees respectively
import rospy
from nav_msgs.msg import Odometry
from tf.transformations import euler_from_quaternion, quaternion_from_euler
print("starting check_yaw_from_odom")
def get_rotation (msg):
@jones2126
jones2126 / transmission_v1.cpp
Created August 28, 2020 21:16
Arduino / Teensy code for ROS serial control of servo
/*
This program is designed to run on a Teensy that is connected to a SuperServo to make the Super Servo ROS enabled and control
the transmission of a lawn tractor. It is started in a launch file as one of multiple nodes with the command:
<node ns="transmission_teensy" name="transmission_cntrl" pkg="rosserial_python" type="serial_node.py" args="/dev/transmission_control" output="screen" />
Overview:
subscribe to a target speed in cmd_vel format (i.e. cmd_vel.linear.x)
subscribe to actual speed from the rear wheels
adjust servo position to match actual speed to target speed
@jones2126
jones2126 / parser.py
Created September 7, 2020 20:55
Parser for NMEA sentences which is part of ROS nmea_navsat_driver updated to output course in radians offset 90 degrees
# Software License Agreement (BSD License)
#
# Copyright (c) 2013, Eric Perko
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright