Skip to content

Instantly share code, notes, and snippets.

View SweiLz's full-sized avatar
🏠
Working from home

Liews Wuttipat SweiLz

🏠
Working from home
View GitHub Profile

For ROS navigation, there is a tf tree map->odom->base_link. The odom pose is the base_link frame pose relative to odom frame. The absolute/global pose is the base_link frame pose relative to map frame. IMU and encoders provide the odom pose which drifts over time and thus only right for a short time. GPS, amcl and indoor position system provide the absolute/global pose. You got odom pose means you got the tf odom->base_link, and you got absolute/global pose means you got base_link pose relative to map. To correct the robot location, you have to provide the tf map->odom, which can be calculated from odom->base_link and base_link pose relative to map.

@SweiLz
SweiLz / conversion_node.cpp
Created February 17, 2019 08:17
ROS Quaternion to RPY
#include <tf/tf.h>
#include <nav_msgs/Odometry.h>
#include <geometry_msgs/Pose2D.h>
ros::Publisher pub_pose_;
void odometryCallback_(const nav_msgs::Odometry::ConstPtr msg) {
geometry_msgs::Pose2D pose2d;
pose2d.x = msg->pose.pose.position.x;
pose2d.y = msg->pose.pose.position.y;
@SweiLz
SweiLz / rospy_publisher.py
Created February 17, 2019 10:25
Rospy publisher
import rospy
from std_msgs.msg import String
pub = rospy.Publisher('topic_name', String, queue_size=10)
rospy.init_node('node_name')
r = rospy.Rate(10) # 10hz
while not rospy.is_shutdown():
pub.publish("hello world")
r.sleep()
#include "ros/ros.h"
#include <diagnostic_msgs/DiagnosticArray.h>
#include <diagnostic_msgs/DiagnosticStatus.h>
#include <diagnostic_msgs/KeyValue.h>
int main(int argc, char **argv)
{
ros::init(argc, argv, "diagnostics");
ros::NodeHandle nh;
#! /usr/bin/env python
import math
import sys
import rospy
import serial
import tf
from geometry_msgs.msg import Twist, Pose2D
from nav_msgs.msg import Odometry
@SweiLz
SweiLz / arduino_SoftwareSerial.ino
Created September 1, 2019 08:29
Arduino Software Serail testcode
#include <SoftwareSerial.h>
SoftwareSerial ss(8, 2); // RX, TX
void setup() {
Serial.begin(115200);
Serial.println("Goodnight moon!");
ss.begin(115200);
ss.println("Hello, world?");
@SweiLz
SweiLz / mbed_i2c_scanner.cpp
Last active June 4, 2020 12:55
I2C address scanner for mbed os
#include <mbed.h>
I2C i2c(PB_11, PB_10); // SDA pin, SCL pin
Serial pc(PB_6, PB_7); // TX pin, RX pin
int main()
{
pc.baud(115200);
wait_ms(2000);
pc.printf("Hello World!\n");
#include <Stepper.h>
const int stepsPerRevolution = 2048;
Stepper myStep = Stepper(stepsPerRevolution,8,10,9,11);
void setup() {
myStep.setSpeed(15); // speed in rpm
Serial.begin(9600);
}
@SweiLz
SweiLz / calculate_crc16.py
Created April 22, 2020 14:44
Function to calculate CRC16 Checksum in python
def updateCRC(crc_accum, data_blk_ptr, data_blk_size):
crc_table = [0x0000,
0x8005, 0x800F, 0x000A, 0x801B, 0x001E, 0x0014, 0x8011,
0x8033, 0x0036, 0x003C, 0x8039, 0x0028, 0x802D, 0x8027,
0x0022, 0x8063, 0x0066, 0x006C, 0x8069, 0x0078, 0x807D,
0x8077, 0x0072, 0x0050, 0x8055, 0x805F, 0x005A, 0x804B,
0x004E, 0x0044, 0x8041, 0x80C3, 0x00C6, 0x00CC, 0x80C9,
0x00D8, 0x80DD, 0x80D7, 0x00D2, 0x00F0, 0x80F5, 0x80FF,
0x00FA, 0x80EB, 0x00EE, 0x00E4, 0x80E1, 0x00A0, 0x80A5,
0x80AF, 0x00AA, 0x80BB, 0x00BE, 0x00B4, 0x80B1, 0x8093,
@SweiLz
SweiLz / calculate_electric_used_unit.py
Created April 22, 2020 14:59
ฟังก์ชั่นคำนวณค่าไฟออกมาเป็นหน่วยบาท
def calUnit(unit,Ft = -11.6):
total = 0
temp_unit = unit
if unit <= 150:
print("Case: ","1.1")
else:
print("Case: ","1.2")
if temp_unit > 400:
total += ((temp_unit-400) * 4.4217)
temp_unit = 400