Pop.CAN

Pop.CAN is easy and fast educational Library for CAN Protocol. It supports can communication and provides motor control and sensor monitoring using CAN communication.



Class Can

Class used whe using CAN interface.

The code to import the Can Class :

from pop.CAN import Can

 Initialization

Can() : Can Object

 Methods

send(msg_id, buf, is_extended=False) : Sends a message via can communication. This method's name in AIoT AutoCAR Prime X, AIoT SerBot Prime X is "write".
  Params
   msg_id : Number of Message ID.
   buf : It is a message to be transmitted through can communication.
   is_extended : Check if the set ID is extended id.

recv(timeOut=2) : Recv a message via can communication. This method's name in AIoT AutoCAR Prime X, AIoT SerBot Prime X is "read".
  Params
   timeOut : Time to wait for message.

setFilter(can_id, mask) : Set the id filter for incoming messages.
  Params
   can_id : Can message id.
   mask : Can message id.



Class Car

This class controls AIoT AutoCar using Can communication.
This class is used in AIoT AutoCAR Prime X, AIoT AutoCAR 2, AIoT AutoCAR 3.

The code to import the Car Class :

from pop.CAN import Car

 Initialization

Car() : Car Object

 Methods

wheel(value) : Set dc motor speed.
  Params
   value : Motor speed, between -100 and 100. 100 is forward 100%. -100 is backward 100%.

steer(value) : Set steer angle.
  Params
   value : Steer angle, between -1 and +1. 0 is center.

camPan(value) : Set camera Pan angle.
  This method is used in AIoT Prime X, AIoT AutoCAR 2.
  Params
   value : Camera Pan angle, between 10 and 170. 90 is center.

camTilt(value) : Set camera Tilt angle.
  This method is used in AIoT Prime X, AIoT AutoCAR 2.
  Params
   value : Camera Tilt angle, between 25 and 135. 90 is center.

ultraEnable(enable=[0x03, 0x03, 0x01]) : Ultrasonic sensor reception status setting.
  Params
   enable : List data with ultrasonic sensor activation information, 1 is activated 0 is disabled. The first factor is the front ultrasonic setup, and the second factor is the rear ultrasonic setup. Bit 0 of each element means left and bit 1 means right. and last factor is interval time(sec) setup.

ultraDisable() : Stop ultrasonic sensor receiving.

imuEnable(enable=[0x0E, 0x01]) : IMU sensor reception status setting.
  This method is used in AIoT AutoCAR 2, AIoT AutoCAR 3.
  Params
   enable : List data with IMU sensor activation information, 1 is activated 0 is disabled. The first factor is the IMU setup, and the second factor is the interval time(sec) setup. In first factor, bit 0 is calibration, bit 1 is accel, bit 2 is magnetic, bit 3 is gyro, bit 4 is euler, bit 5 is gravity.

imuDisable() : Stop IMU sensor receiving.
  This method is used in AIoT AutoCAR 2, AIoT AutoCAR 3.

calibrationEnable(enable=[0x01, 0x01]) : IMU sensor reception status setting.
  This method is used in AIoT AutoCAR 2, AIoT AutoCAR 3.
  Params
   enable : List data with IMU sensor activation information, 1 is activated 0 is disabled. The first factor is the IMU setup, and the second factor is the interval time(sec) setup. In first factor, bit 0 is calibration, bit 1 is accel, bit 2 is magnetic, bit 3 is gyro, bit 4 is euler, bit 5 is gravity.

cdsEnable(enable=[0x01]) : Cds sensor reception status setting.
  This method is used in AIoT AutoCAR 2, AIoT AutoCAR 3.
  Params
   enable : List data is the interval time(sec) setup.

cdsDisable() : Stop cds sensor receiving.
  This method is used in AIoT AutoCAR 2, AIoT AutoCAR 3.

battEnable(enable=[0x01]) : Battery voltage reception status setting.
  This method is used in AIoT AutoCAR 2, AIoT AutoCAR 3.
  Params
   enable : List data is the interval time(sec) setup.

battDisable() : Stop battery voltage receiving.
  This method is used in AIoT AutoCAR 2, AIoT AutoCAR 3.

setObstacleDistance(distance = 20) : Obstacle detection distance setting.
  This method is used in AIoT AutoCAR 2, AIoT AutoCAR 3.
  Params
   distance : Set obstacle distance. 20 < range <= 180. If distance set below 20, obstacle distance function disable.

readStart() : Read thread start.

readStop() : Read thread stop.

readUltra() : Return ultrasonic sensor as list. [front0, front1, rear0, rear1]
  This method's name in AIoT AutoCAR Prime X is "read".

readAccel() : Return accel sensor as list. [x,y,z]
  This method is used in AIoT AutoCAR 2, AIoT AutoCAR 3.

readMagnetic() : Return magnetic sensor as list. [x,y,z]
  This method is used in AIoT AutoCAR 2, AIoT AutoCAR 3.

readGyro() : Return gyro sensor as list. [x,y,z]
  This method is used in AIoT AutoCAR 2, AIoT AutoCAR 3.

readEuler() : Return euler sensor as list. [x,y,z]
  This method is used in AIoT AutoCAR 2, AIoT AutoCAR 3.

readGravity() : Return gravity sensor as list. [x,y,z]
  This method is used in AIoT AutoCAR 2, AIoT AutoCAR 3.

imu_calibration() : Return IMU calibration result. bit0~1 is mag, bit 2~3 is accel, bit4~5 is gyro, bit6~7 is sys.
  This method is used in AIoT AutoCAR 2, AIoT AutoCAR 3.

readCds() : Return cds sensor as int.
  This method is used in AIoT AutoCAR 2, AIoT AutoCAR 3.

readBattery() : Return Battery voltage.
  This method is used in AIoT AutoCAR 2, AIoT AutoCAR 3.

lampControl(front=0, rear=0) : Set lamp on/off.
  This method is used in AIoT AutoCAR 2, AIoT AutoCAR 3.
  Params
   front : Front lamp on(1)/off(0)
   rear : Rear lamp on(1)/off(0)

alarm(scale,pitch,duration=0) : Control buzzer.
  This method is used in AIoT AutoCAR 2, AIoT AutoCAR 3.
  Params
   scale : Set scale
   pitch : Set pitch
   duration : Set duration

PixelDisplay(num, red, green=0, blue=0) : Set PixelDisplay.
  This method is used in AIoT AutoCAR 2.
  Params
   num : Pixel display number. 0~255
   red : Red value. 0~255
   green : Green value. 0~255
   blue : Blue value. 0~255



Class OmniWheel

This class controls OmniWheel using Can communication.
This class is used in AIoT SerBot Prime X.

The code to import the OmniWheel Class :

from pop.CAN import OmniWheel
 Initialization

OmniWheel() : OmniWheel Object

 Variables

ULTRASONIC : Constant for reading ultrasonic sensor data.
PSD : Constant for reading PSD sensor data.
ALARM : Constant for reading Obstacle Detect Alarm.
SENSOR_ALL : Constant for reading All sensor data.

 Methods

forward(data) : Method used to move the wheel forward.
  Params
   data : List including motor speed, input motor 1,2,3 in sequence, integer between 0 and 100, and if 100, motor operates at 100% speed

backward(data) : Method used to move the wheel backward.
  Params
   data : List including motor speed, input motor 1,2,3 in sequence, integer between 0 and 100, and if 100, motor operates at 100% speed

setObstacleRange(ultra_distance, psd_distance) : Obstacle detection distance setting
   When the two values are the same -> No notification, only detection, motor stops when detected.
   When the two values are not the same -> Only the notification message is delivered between the maximum and minimum values.
   When the two values are not the same -> Motor stop and notification message when it is less than the minimum value.
  Params
   ultra_distance : Ultrasonic sensor detection distance.
   psd_distance : PSD sensor detection distance

stop() : Method used to Motor stop

allSensorEnable() : Method used to receive all sensor data from the Omni Wheel

ultraEnable(enable=[1,1,1,1,1,1]) : Ultrasonic sensor reception status setting.
  Params
   enable : List data with ultrasonic sensor activation information, 1 is activated 0 is disabled.

psdEnable(enable=[1,1,1]) : PSD sensor reception status setting.
  Params
   enable : List data with PSD sensor activation information, 1 is activated 0 is disabled

getEnable() : Return sensor reception status.

sensorDisable() : Disable sensor reception.

read(msgType) : Reading messages received on the Omni wheel via CAN communication.
  Params
   msgType : There are 4 types of data to be passed to msgType.
    SENSORALL : Constant for reading All sensor data.
    ULTRASONIC : Constant for reading ultrasonic sensor data.
    PSD : Constant for reading PSD sensor data.
    ALARM : Constant for reading Obstacle Detect Alarm.

setCallback(func,param=None) : Set up callback function for Obstacle Alarm
  Params
   func : Function to use when calling Callback
   param : Parameters passed to the Callback function , Default None